swing学习1--swing的HelloWorld
package swing;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class HelloWorld {
private static void createAndShowGUI(){
//设置界面的 外观为漂亮
JFrame.setDefaultLookAndFeelDecorated(true);
//设置窗口标题
JFrame frame = new JFrame("hellowWorldSwing");
/*设置关闭(x)的作用
默认:HIDE_ON_CLOSE,隐藏窗口
DO_NOTHING_ON_CLOSE,不操作
DISPOSE_ON_CLOSE,自动隐藏后 释放窗口
EXIT_ON_CLOSE:退出程序*/
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//创建一个窗体内容
JLabel label = new JLabel("hello world");
//将窗体内容添加到窗口中
frame.getContentPane().add(label);
//根据窗口界面内的内容布局确定大小
frame.pack();
//设置窗口显示
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable(){
public void run(){
createAndShowGUI();
}
});
}
}

浙公网安备 33010602011771号