首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

Dialog的模态有关问题

2012-08-07 
Dialog的模态问题package mycheckboximport java.awt.*import java.awt.event.ActionEventimport java.

Dialog的模态问题
package mycheckbox;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyDialog extends Frame
{
 private Button but1,but2,but3;
 private TextField tf;
 private Dialog dl;
 private static MyDialog md;
public static void main(String[] args)  
{
 md=new MyDialog();
}
MyDialog()
{
this.setLayout(new FlowLayout());
but1 =new Button("静态模式");
this.add(but1);
but1.addActionListener(new Girl());
but2 =new Button("非静态模式");
this.add(but2);
but2.addActionListener(new Girl());
tf=new TextField(30);
this.add(tf);
dl=new Dialog(md,"对话框",true);
but3=new Button("退出");
dl.add(but3);
dl.setSize(200, 300);
but3.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
  dl.dispose();
  }
  });
this.setSize(300, 350);
this.setVisible(true);
}

class Girl implements ActionListener
{
  public void actionPerformed(ActionEvent e) {
  if(e.getSource()==but1)
  { tf.setText("静态模式");
  dl.setVisible(true);
  dl.setModal(true);
   
  }
  else
  if(e.getSource()==but2)
  {tf.setText("非静态模式");
  dl.setVisible(true);
  dl.setModal(false);  
  }
  }

}
}

上面是我写的程序,但是为什么两个都是模态对话框?怎么dl.setModal(false);这句话并没有其作用呢?是不是和执行的先后顺序有关?
希望高手教我!

[解决办法]
只要是模态对话框
在 setVisible(true); 之后的语句将会被阻塞
直到这个对话框不可见为止

你可以放过来写
dl.setModal(false);
dl.setVisible(true);

热点排行