swing怎么创建模式窗体?急~~在线等 假如有两个JFrame窗体:jf1与jf2,在jf1上有个JButton:jb,在jb的事件里触发jf2显示,可以使jf2成为模式窗体吗?如果不行的话还有其它的办法吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 jf2不继承JFrame,改继续JDialog窗体类就可以了。 楼上说的那样,用这个构造方法:JDialog(Frame owner, boolean modal) owner - 显示该对话框的 Framemodal - 为 true 时是有模式对话框,false 时允许其他窗口同时处于激活状态 能给我写个列子吗,我对JDialog 不熟悉,先谢谢了 public class Test { /** * @param args */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub JFrame frame = new DialogTest(); }}class DialogTest extends JFrame{ public DialogTest(){ this.setTitle("menu text"); this.setSize(500,600); this.setVisible(true); dialog = new JDialog(); dialog.setSize(200, 100); dialog.setModal(true); JButton button = new JButton("显示"); button.setSize(50, 20); this.getContentPane().add(button); button.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent event) { // TODO Auto-generated method stub dialog.show(); }}); } private JDialog dialog;} public void jMenuItem1_actionPerformed(ActionEvent e) { FormAddCla formaddcla = new FormAddCla(); formaddcla.setSize(400,300); formaddcla.setLocationRelativeTo(null); formaddcla.setResizable(false); //formaddcla.setVisible(true); JDialog jd = new JDialog(formaddcla,"添加班级",true); jd.setSize(400,300); jd.setLocationRelativeTo(null); jd.setResizable(false); jd.setVisible(true); }我这个该怎么改? public class MyFrame extends JFrame{public MyFrame(){JButton jb = new JButton("添加班级");jb.addActionListener(new ActionListener(){createClass();});getContentPane().add(jb);this.setSize(new Dimension(100,100));}private void createClass(){JDialog dialog = new JDialog(this,"添加班级",true);dialog.setVisible(true);}public static void main(String[] args){MyFrame frame = new MyFrame();frame.setVisible(true);}} 其实两个Frame也可以实现模式窗体,只不过得自己通过监听实现,如果模式窗体显现,如果LostFocus,就将FocusEvent消费掉 public void this_windowClosing(WindowEvent e) { int s = JOptionPane.showConfirmDialog(this,"确定退出系统吗?","退出系统",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE); if(s == JOptionPane.OK_OPTION){ System.exit(0); }else{ return; } }我点“确定”窗体可以退出,如果点“撤销”或点关闭图标,窗体隐藏了不会退出?? 高分!!请大家来看下,旺旺登录接口的加密字符串!!! ant 中的taskdef 有没有办法向java类传递参数 Spring Security3 有关权限的问题 请帮我解释一下! java table 滚动条 急急急 返回值return的用处是什么? 怎样才能学好用好JAVA? 请问jdbc中,如何获得表名 eclipse Run 的时候出现在“Compute launch button tooltip”期间发生了内部错误。 MALFORMED 程序题求解答 巨神的问题!! String Method ????
JDialog(Frame owner, boolean modal) owner - 显示该对话框的 Frame
modal - 为 true 时是有模式对话框,false 时允许其他窗口同时处于激活状态
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
JFrame frame = new DialogTest();
}
}class DialogTest extends JFrame{
public DialogTest(){
this.setTitle("menu text");
this.setSize(500,600);
this.setVisible(true);
dialog = new JDialog();
dialog.setSize(200, 100);
dialog.setModal(true);
JButton button = new JButton("显示");
button.setSize(50, 20);
this.getContentPane().add(button);
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent event) {
// TODO Auto-generated method stub
dialog.show();
}});
}
private JDialog dialog;
}
FormAddCla formaddcla = new FormAddCla();
formaddcla.setSize(400,300);
formaddcla.setLocationRelativeTo(null);
formaddcla.setResizable(false);
//formaddcla.setVisible(true);
JDialog jd = new JDialog(formaddcla,"添加班级",true);
jd.setSize(400,300);
jd.setLocationRelativeTo(null);
jd.setResizable(false);
jd.setVisible(true);
}
我这个该怎么改?
public MyFrame(){
JButton jb = new JButton("添加班级");
jb.addActionListener(new ActionListener(){
createClass();
});getContentPane().add(jb);this.setSize(new Dimension(100,100));
}private void createClass(){
JDialog dialog = new JDialog(this,"添加班级",true);
dialog.setVisible(true);
}public static void main(String[] args){
MyFrame frame = new MyFrame();
frame.setVisible(true);
}
}
public void this_windowClosing(WindowEvent e) {
int s = JOptionPane.showConfirmDialog(this,"确定退出系统吗?","退出系统",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
if(s == JOptionPane.OK_OPTION){
System.exit(0);
}else{
return;
}
}
我点“确定”窗体可以退出,如果点“撤销”或点关闭图标,窗体隐藏了不会退出??