假如有两个JFrame窗体:jf1与jf2,在jf1上有个JButton:jb,在jb的事件里触发jf2显示,可以使jf2成为模式窗体吗?如果不行的话还有其它的办法吗?

解决方案 »

  1.   

    jf2不继承JFrame,改继续JDialog窗体类就可以了。
      

  2.   

    楼上说的那样,用这个构造方法:
    JDialog(Frame owner, boolean modal) owner - 显示该对话框的 Frame
    modal - 为 true 时是有模式对话框,false 时允许其他窗口同时处于激活状态 
     
      

  3.   

    能给我写个列子吗,我对JDialog 不熟悉,先谢谢了
      

  4.   

    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;
    }
      

  5.   

    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);
        }
    我这个该怎么改?
      

  6.   

    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);
    }
    }
      

  7.   

    其实两个Frame也可以实现模式窗体,只不过得自己通过监听实现,如果模式窗体显现,如果LostFocus,就将FocusEvent消费掉
      

  8.   


    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;
            }
        }
    我点“确定”窗体可以退出,如果点“撤销”或点关闭图标,窗体隐藏了不会退出??