简体   繁体   中英

How to start a new GUI form in IntelliJ IDEA?

IntelliJ IDEA uses a different approach to GUI forms, instead of extending JFrame, it hides all GUI code in .form files and instantiates the form in main() of Bound class.

Now for example, I have two forms in the project. Login and Page.

In any other IDE, I would have called Page.java after successful login using

Page page = new Page();
page.setVisible(true);

it works because Page extends JFrame class and thus has setVisible() method. But how do I do that in Intellij?

Edit: Page.java

public class Page {
    private JButton uploadAFileButton;
    private JPanel panel1;
    private JButton downloadSelectedFileButton;
    private JButton deleteSelectedFileButton;
    private JList list1;
    private JButton refreshFileListButton;

    public static void main(String[] args) {
        JFrame frame = new JFrame("ControlForm");
        frame.setContentPane(new Page().panel1);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}

if page class is GUI form,the you should extend it using JFrame. If not you can't call page.setVisible(true); .So your page class should be like this.

public class Page extends JFrame {
    private JButton uploadAFileButton;
    private JPanel panel1;
    private JButton downloadSelectedFileButton;
    private JButton deleteSelectedFileButton;
    private JList list1;
    private JButton refreshFileListButton;
}

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