Adding label and text box control to GUI

后端 未结 2 675
小鲜肉
小鲜肉 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");
    

提交回复
热议问题