找到原因了,错误提示错了,没有import包的名称

解决方案 »

  1.   

    JDialog有设置modal的参数
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;class MyDialog extends JDialog{
        public MyDialog(){
            this((JFrame)null, "dialog", true);
        }
        
        public MyDialog(JFrame frame){
            this(frame, "dialog", true);
        }
        public MyDialog(JFrame frame, String title, boolean modal) {
            super(frame, title, modal);
            setResizable(false);
            setSize(300, 300);
            setLocationByPlatform(true);
            setLocationRelativeTo(frame);
            add(new JLabel("Hello Dialog"));
        }
        }
    public class Demo extends JFrame{
        private JButton jbtnHello = new JButton("dialog");    public Demo() {
            setTitle("demo");
            setSize(800,600);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            jbtnHello.addActionListener(new ActionListener() {
                
                @Override
                public void actionPerformed(ActionEvent e) {
                    MyDialog dialog = new MyDialog(Demo.this);
                    dialog.setVisible(true);
                }
            });
            setLayout(new FlowLayout()); 
            add(jbtnHello);
        }    public static void main(String[] args) {
            Demo demo = new Demo();
            demo.setVisible(true);
        }
    }