开发者

Making a hello world app in a Form in Intellij

I'm trying to make a hello world form in Intellij. I've created the 开发者_开发技巧form, but the question now is what code to make in main() to make the form run and show up?

PS: all the tutorials around seem to only focus on "how to do forms on intellij" not in "how to actually make it run, then".

Thanks


  1. Go to the class with the same name as the form.
  2. Press the keyboard shortcut for "Generate". It's Ctrl+N on Mac OS X, Alt+Ins on Windows. Alternatively, from the menu, select menu Code → Generate.

  3. Select "Form main()".

Now the main method is written and inserted for you. It will look something like this:

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


I just did my first Intellij Swing App. Steve McLeod has the right instructions, however, when I tried to generate the main method using Alt+Insert => Generate main, I received an error message about one of my panels not being bound. So I clicked on the gui designer page (.form), selected my top panel, and gave it a name.

Everything else was named for me, but for some reason, the panel name was blank. Once I did that, I was able to switch over to the form .java class, press "Alt+Insert" and generate a constructor (not required, but needed).

From there, I followed Steve's advice to generate a main method. One thing that threw me off was the expectation that my Intellij generated .java class would extend or implement something swing related - it didn't. Swing only shows up in the Intellij generated main method (besides the private variables).


Check this tut while it is realy step-by-step:

JetBrains JavaFX HelloWorld

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜