随意创建一个JFrame窗口,再以它为父窗口创建一个JDialog,JDialog(Frame owner, String title, boolean modal)如果JDialog为模式对话框的话它上面的按钮的监听会失效(按上去没反应),而如果改为非模式对话框,监听就有反应了,这是为什么啊???
解决方案 »
- 请教个java执行存储过程的问题,希望大家积极解答,多谢了!
- 请问服务器连接多个客户需要建立多个accept()吗
- 在JCreator中输入中文显示乱码,要怎么设置才能显示正常呢?
- 关于GUI和数据库的应用程序问题
- string的哪个函数可以比较一个string包含另一个string?
- 我下载了SunOne Studio 4多语言版,但是安装后是英文,怎么改语言啊?我找不到地方!
- 我刚做的一个共享程序,主要的部分都已经完成了,就差一个多线程下载,请各位高手帮帮忙呀.
- 大家来谈谈阅读thking in java 第15章(分布式计算)的感受,,
- 请教在这个程序里的变量类型为什么用float而不用short
- 有关ArrayList的问题!!
- 利用JAVA制作一个网上发牌程序
- [讨论]应该如何有效的去设计GUI,为以后的MOD和REUSE 铺垫?
import java.awt.event.*;
public class Test {
private JFrame frame = null;
private JDialog dialog = null;
private JButton button = null;
private JButton b_Dialog = null;
private JButton b_close = null;
private JLabel label = null;
private int i = 0; public Test(){
frame = new JFrame("JDialog");
button = new JButton("测试窗口");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
dialogFrame();
}
});
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.getContentPane().add(button);
frame.setSize(300, 200);
frame.setVisible(true); } public void dialogFrame(){
i = 0;
dialog = new JDialog(frame, true);
JPanel pane = new JPanel();
b_Dialog = new JButton("开始测试");
b_close = new JButton("关闭窗口");
label = new JLabel(i + "");
b_Dialog.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
label.setText(++i + "");
}
});
b_close.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
});
pane.add(b_Dialog);
pane.add(label);
pane.add(b_close);
dialog.getContentPane().add(pane);
dialog.setSize(230, 80);
dialog.setVisible(true);
} public static void main(String[] args) {
new Test();
}
}