简体   繁体   中英

Java how to start up the GUI made with IntelliJ IDEA

I have made a simple GUI using IntelliJ-IDEA and I can't figure out how to start it up. Something like Form1 f = new Form(); inside my main() function doesn't seem to do anything. Does anyone know how to start it up ?

public class Main {

    public static void main(String[] args) {
        System.out.println("Hello World!");
        Form1 t = new Form1();
    }
}

1个

I had to add a couple of lines more than expected. Here is how my working code looks like for the Form1.java file. I didn't change my main() fucntion.

public class Form1 extends JFrame {

    // ******** These are just auto-generated from the IDE ********
    private JPanel panel1;
    private JButton button1;
    private JButton bb137;
    private JButton button3;
    private JButton button4;
    private JButton button5;
    private JButton button6;
    private JButton button7;
    private JCheckBox checkBox1;
    private JRadioButton radioButton1;
    private JRadioButton radioButton2;
    private JRadioButton radioButton3;
    // ************************************************************

    public Form1(){
        super("Whatever form title here.");
        // panel1 is my main panel as you can see in my question's screenshot
        setContentPane(panel1); 
               //x , y, width, height
        setBounds(300,300,600,600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM