Netbeans GUI编辑器生成自己难以理解的代码 [英] Netbeans GUI editor generating its own incomprehensible code
问题描述
在netbeans中创建一个新项目时,如果我选择JAVA Desktop应用程序,它会创建一些我根本无法识别的代码,就像我在摇摆中学到的那样。
When creating a new project in netbeans, if i select JAVA Desktop application, it creates some code which I DO NOT RECOGNISE AT ALL as what i had learnt in swing.
它导入包,例如:
org.jdesktop.application.SingleFrameApplication;
此外,main()的声明如下:
also, the declaration for main() looks like this :
public static void main(String[] args) {
launch(DesktopApplication2.class, args);
}
这对我对JFrame,JPanel等的了解毫无意义。 。
This really does not make any sense to my knowledge of JFrame, JPanel etc..
如果我尝试从头编写netbeans应用程序,我可以编写自己的swing应用程序,但我找不到GUI编辑器。
If i try to code a netbeans application from scratch, i can write my own swing app BUT I CANNOT FIND THE GUI EDITOR.
- 从头开始创建Java应用程序时如何使用GUI编辑器?
- 任何人都可以向我解释这个org.jdesktop.application .SingleFrameApplication和其他类?
请帮忙。这真是令人沮丧。
Please help. This is really frustrating.
推荐答案
您可能无意中选择了 Java桌面应用程序
基于 Swing应用程序框架(JSR 296)。此模板提供基本的应用程序基础结构,例如菜单栏,窗口状态的持久性和状态栏。使用此模板,您还可以生成代码以创建数据库表的GUI界面。
Creates a skeleton of a desktop application based on the Swing Application Framework (JSR 296). This template provides basic application infrastructure such as a menu bar, persisting of window state, and status bar. With this template, you can also generate code to create a GUI interface for a database table.
而不是 Java应用程序
在标准IDE项目中创建新的Java SE应用程序。您还可以在项目中生成主类。标准项目使用IDE生成的Ant构建脚本来构建,运行和调试项目。
Creates a new Java SE application in a standard IDE project. You can also generate a main class in the project. Standard projects use an IDE-generated Ant build script to build, run, and debug your project.
附录:使用文件>新文件> Java GUI Forms
添加高级容器,例如一个封闭的 JPanel
,可以从 main()实现
的 run()
方法。
Addendum: Use File > New File > Java GUI Forms
to add high-level containers, e.g. an enclosing JPanel
, that can be instantiated from main()
's run()
method.
例如, Main.main()
:
package temp;
import java.awt.EventQueue;
import javax.swing.JFrame;
public class Main {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new NewJPanel());
f.pack();
f.setVisible(true);
}
});
}
}
以及 NewJPanel
在GUI编辑器中构建(注意Generated Code):
And a NewJPanel
built in the GUI editor (note "Generated Code"):
package temp;
public class NewJPanel extends javax.swing.JPanel {
/** Creates new form NewJPanel */
public NewJPanel() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel1.setText("Hello, world!");
org.jdesktop.layout.GroupLayout layout =
new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(163, 163, 163)
.add(jLabel1)
.addContainerGap(157, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(113, 113, 113)
.add(jLabel1)
.addContainerGap(171, Short.MAX_VALUE))
);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
这篇关于Netbeans GUI编辑器生成自己难以理解的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!