网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

java swing的图形界面hello world

时间:2024-10-17 08:01:06

1、使用eclipse创建一个项目名字为Test,并创建com.cn.Test 类。

java swing的图形界面hello world

2、编写main方法:public class Test{ public static void main(String[] args) { // TODO Auto-generated method stub }}

java swing的图形界面hello world

3、继承JFrame。public class Test extends JFrame

java swing的图形界面hello world

4、创建一个窗口,代码: mainFrame = new JFrame("第一个程序"); mainFrame.setSize(500,500);

java swing的图形界面hello world

5、向窗口中增加面板,增加lable:JPanel panel = new JPanel(); mainFrame.add(panel); JLabel userLabel = new JLabel("hello world"); userLabel.setBounds(20,30,80,25); panel.add(userLabel);

java swing的图形界面hello world

6、设置窗口可见。mainFrame.setVisible(true);

java swing的图形界面hello world

7、运行程序,弹出窗口 hello world。完成第一个java swing程序。

java swing的图形界面hello world
© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com