简体   繁体   English

在Intellij的表单中制作一个hello world应用程序

[英]Making a hello world app in a Form in Intellij

I'm trying to make a hello world form in Intellij. 我正试图在Intellij中制作一个hello world form。 I've created the form, but the question now is what code to make in main() to make the form run and show up? 我已经创建了表单,但现在的问题是在main()中使用什么代码来使表单运行并显示?

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". PS:周围的所有教程似乎只关注“如何在intellij上做表格”,而不是“如何实际运行,然后”。

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. 它是Mac OS X上的Ctrl + N ,Windows上的Alt + Ins Alternatively, from the menu, select menu Code → Generate. 或者,从菜单中选择菜单代码→生成。

  3. Select "Form main()". 选择“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. 我刚刚完成了我的第一个Intellij Swing应用程序。 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. 史蒂夫麦克劳德有正确的指示,但是,当我尝试使用Alt + Insert => Generate main生成主方法时,我收到一条关于我的某个面板没有被绑定的错误消息。 So I clicked on the gui designer page (.form), selected my top panel , and gave it a name. 所以我点击了gui设计器页面(.form),选择了我的顶部面板 ,并给它起了一个名字。

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). 一旦我这样做,我就可以切换到表单.java类,按“Alt + Insert”并生成一个构造函数(不是必需的,但需要)。

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. 让我失望的一件事是期望我的Intellij生成的.java类会扩展或实现与swing相关的东西 - 它没有。 Swing only shows up in the Intellij generated main method (besides the private variables). Swing只出现在Intellij生成的main方法中(除私有变量外)。

Check this tut while it is realy step-by-step: 一步一步地检查这个tut:

JetBrains JavaFX HelloWorld JetBrains JavaFX HelloWorld

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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