一、常用窗体
1. JFrame框架窗体
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16public class TestJFrame { public void init(){ JFrame jframe = new JFrame("Jframe窗体"); jframe.setBackground(Color.blue); jframe.setBounds(200,200,500,500); jframe.setVisible(true); jframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//关闭窗体 } public static void main(String[] args) { new TestJFrame().init(); } }
常用的窗体关闭方式有四种:
- “DO_NOTHING_ON_CLOSE” :什么也不做就将窗体关闭;
- “DISPOSE_ON_CLOSE” :任何注册监听程序对象后会自动隐藏并释放窗体;
- “HIDE_ON_CLOSE” : 隐藏窗口的默认窗口关闭;
- “EXIT_ON_CLOSE”:退出应用程序默认窗口关闭。
2、Jlable和Container
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29public class TestJFrame extends JFrame{ public void init(){ setBackground(Color.blue); setBounds(200,200,500,500); setVisible(true); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JLabel label = new JLabel("这是一个标签"); label.setHorizontalAlignment(SwingConstants.CENTER);//设置标签居中 add(label); Container contentPane = this.getContentPane();//获得容器 contentPane.add(label); contentPane.setVisible(true); contentPane.setBackground(Color.red); } public static void main(String[] args) { new TestJFrame().init(); } }
最后
以上就是执着摩托最近收集整理的关于JAVA的GUI编程04——Swing(JFrame框架窗体、Jlable和Container)一、常用窗体 的全部内容,更多相关JAVA的GUI编程04——Swing(JFrame框架窗体、Jlable和Container)一、常用窗体内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复