Adding label and text box control to GUI

后端 未结 2 672
小鲜肉
小鲜肉 2021-01-26 13:44

I would like to know what code to insert and where to add a simple label that can just say the word \"Label\" and a input text box that I can enter a number.

pub         


        
相关标签:
2条回答
  • 2021-01-26 14:17

    in your public static void main() method you should not instantiate JFrame frame = new JFrame("Calculations");

    This is where you are going wrong!

    That line should read:

    CalculateDimensions frame = new CalculateDimensions("Calculations");
    

    You will also need to change the line says

    public class CalculateDimensions {
    

    (it's near the top) says

    public class CalculateDimensions extends JFrame {
    

    then inside the method called public class CalculateDimensions { you need to add a line after JPanel jplInnerPanel1 = createInnerPanel("First Tab"); which says

    jplInnerPanel1.add(new JLabel("Label");
    
    0 讨论(0)
  • 2021-01-26 14:23

    The Swing tutorial is an excellent resource for building GUIs.

    Take a look at the visual guide and click on the components you want for detailed how to guides for creating text boxes, and other items.

    http://download.oracle.com/javase/tutorial/ui/features/components.html

    0 讨论(0)
提交回复
热议问题