当前位置:首页 » 编程语言 » javaswing窗口

javaswing窗口

发布时间: 2023-09-26 07:26:56

java swing 窗体关闭的方法 有哪些

Jframe的关闭方法:

setDefaultCloseOperation(EXIT_ON_CLOSE);

frame的关闭方法如下:

this.addWindowListener(new java.awt.event.WindowAdapter() {

public void windowClosing(java.awt.event.WindowEvent e) {

System.exit(0);

}

});
一般两种方法:
一种是System.exit(0);
另一种是setVisible(false);

⑵ java swing 编程中,如何实现点击按钮弹出新的窗口

import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
public class Demo {
public static void main(String[] args) {
Demo demo = new Demo();
demo.run();
}

public void run() {
JFrame frame = new JFrame("title1");
frame.setLayout(null);
frame.setBounds(10, 10, 500, 300);

Button button = new Button("click");
button.setBounds(15, 15, 200, 100);
frame.add(button);
frame.setVisible(true);

button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame("title2");
frame.setLayout(null);
frame.setBounds(20, 20, 300, 100);
frame.setVisible(true);
}
});
}
}
哪里不懂可以追问,很简陋的程序哈。

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:645
制作脚本网站 发布:2025-10-20 08:17:34 浏览:936
python中的init方法 发布:2025-10-20 08:17:33 浏览:632
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:821
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:731
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1066
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:299
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:160
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:852
python股票数据获取 发布:2025-10-20 07:39:44 浏览:763