Java 手工编写GUI和Netbeans
我即将开始学习编写GUI。现在我知道,如果你第一次手工编写代码来掌握概念,那就最好了 我的问题是:我是否需要禁用Netbeans中的GUI构建器来实现这一点?查阅了Netbeans论坛,但找不到明确的答案。似乎大多数程序员仍然更喜欢手工编码选项Java 手工编写GUI和Netbeans,java,Java,我即将开始学习编写GUI。现在我知道,如果你第一次手工编写代码来掌握概念,那就最好了 我的问题是:我是否需要禁用Netbeans中的GUI构建器来实现这一点?查阅了Netbeans论坛,但找不到明确的答案。似乎大多数程序员仍然更喜欢手工编码选项 谢谢您的关注不,您不必禁用任何功能。您可以立即开始编写Swing代码 通过粘贴程序的源代码并运行它,您可以自己尝试一下。以下是一个缩写版本: import javax.swing.*; public class HelloWorldSw
谢谢您的关注不,您不必禁用任何功能。您可以立即开始编写Swing代码 通过粘贴程序的源代码并运行它,您可以自己尝试一下。以下是一个缩写版本:
import javax.swing.*;
public class HelloWorldSwing {
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add the ubiquitous "Hello World" label.
JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
Swing不需要任何额外的东西就可以启动,举个例子
import javax.swing.JFrame;
import javax.swing.JLabel;
public class HelloWorldFrame extends JFrame {
//Programs entry point
public static void main(String args[]) {
new HelloWorldFrame();
}
//Class Constructor to create components
HelloWorldFrame() {
JLabel jlbHelloWorld = new JLabel("Hello World");
add(jlbHelloWorld); //Add the label to the frame
this.setSize(100, 100); //set the frame size
setVisible(true); //Show the frame
}
}
注意:这是运行极其简单版本的最低要求@aioobe是更标准的方法,但需要理解更多的概念:)+1努力理解流程!