问题表现如下
1.通过jbuilder2006向导建立一只Application1程序.
2.在这支package上向导建立一只Dialog1.
3.在Application1的Frame1上的menu添加一个菜单项
4.添加menu的代码如下
   public void jMenuItem1_actionPerformed(ActionEvent e) {
        Dialog1 D = new Dialog1(this);//此语句出错
        
    }
    为何调用Dialog1出错,提示如下
     canno find symbol:constructor....
     internal error:cannot instantiate...谁能帮我?

解决方案 »

  1.   

    package untitled1;import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JMenuBar;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.JToolBar;
    import javax.swing.JButton;
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;/**
     * <p>Title: </p>
     *
     * <p>Description: </p>
     *
     * <p>Copyright: Copyright (c) 2007</p>
     *
     * <p>Company: </p>
     *
     * @author not attributable
     * @version 1.0
     */
    public class Frame1 extends JFrame {
        JPanel contentPane;
        BorderLayout borderLayout1 = new BorderLayout();
        JMenuBar jMenuBar1 = new JMenuBar();
        JMenu jMenuFile = new JMenu();
        JMenuItem jMenuFileExit = new JMenuItem();
        JMenu jMenuHelp = new JMenu();
        JMenuItem jMenuHelpAbout = new JMenuItem();
        JToolBar jToolBar = new JToolBar();
        JButton jButton1 = new JButton();
        JButton jButton2 = new JButton();
        JButton jButton3 = new JButton();
        ImageIcon image1 = new ImageIcon(untitled1.Frame1.class.getResource(
                "openFile.png"));
        ImageIcon image2 = new ImageIcon(untitled1.Frame1.class.getResource(
                "closeFile.png"));
        ImageIcon image3 = new ImageIcon(untitled1.Frame1.class.getResource(
                "help.png"));
        JLabel statusBar = new JLabel();
        JMenuItem jMenuItem1 = new JMenuItem();    public Frame1() {
            try {
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                jbInit();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }    /**
         * Component initialization.
         *
         * @throws java.lang.Exception
         */
        private void jbInit() throws Exception {
            contentPane = (JPanel) getContentPane();
            contentPane.setLayout(borderLayout1);
            setSize(new Dimension(400, 300));
            setTitle("Frame Title");
            statusBar.setText(" ");
            jMenuFile.setText("File");
            jMenuFileExit.setText("Exit");
            jMenuFileExit.addActionListener(new Frame1_jMenuFileExit_ActionAdapter(this));
            jMenuHelp.setText("Help");
            jMenuHelpAbout.setText("About");
            jMenuHelpAbout.addActionListener(new
                                             Frame1_jMenuHelpAbout_ActionAdapter(this));
            jMenuItem1.setText("AA");
            jMenuItem1.addActionListener(new Frame1_jMenuItem1_actionAdapter(this));
            jMenuBar1.add(jMenuFile);
            jMenuFile.add(jMenuItem1);
            jMenuFile.add(jMenuFileExit);
            jMenuBar1.add(jMenuHelp);
            jMenuHelp.add(jMenuHelpAbout);
            setJMenuBar(jMenuBar1);
            jButton1.setIcon(image1);
            jButton1.setToolTipText("Open File");
            jButton2.setIcon(image2);
            jButton2.setToolTipText("Close File");
            jButton3.setIcon(image3);
            jButton3.setToolTipText("Help");
            jToolBar.add(jButton1);
            jToolBar.add(jButton2);
            jToolBar.add(jButton3);
            contentPane.add(jToolBar, BorderLayout.NORTH);
            contentPane.add(statusBar, BorderLayout.SOUTH);
        }    /**
         * File | Exit action performed.
         *
         * @param actionEvent ActionEvent
         */
        void jMenuFileExit_actionPerformed(ActionEvent actionEvent) {
            System.exit(0);
        }    /**
         * Help | About action performed.
         *
         * @param actionEvent ActionEvent
         */
        void jMenuHelpAbout_actionPerformed(ActionEvent actionEvent) {
            Frame1_AboutBox dlg = new Frame1_AboutBox(this);
            Dimension dlgSize = dlg.getPreferredSize();
            Dimension frmSize = getSize();
            Point loc = getLocation();
            dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                            (frmSize.height - dlgSize.height) / 2 + loc.y);
            dlg.setModal(true);
            dlg.pack();
            dlg.setVisible(true);
        }    public void jMenuItem1_actionPerformed(ActionEvent e) {
            Dialog1 D = new Dialog1(this);
            
        }
    }
    class Frame1_jMenuFileExit_ActionAdapter implements ActionListener {
        Frame1 adaptee;    Frame1_jMenuFileExit_ActionAdapter(Frame1 adaptee) {
            this.adaptee = adaptee;
        }    public void actionPerformed(ActionEvent actionEvent) {
            adaptee.jMenuFileExit_actionPerformed(actionEvent);
        }
    }
    class Frame1_jMenuItem1_actionAdapter implements ActionListener {
        private Frame1 adaptee;
        Frame1_jMenuItem1_actionAdapter(Frame1 adaptee) {
            this.adaptee = adaptee;
        }    public void actionPerformed(ActionEvent e) {
            adaptee.jMenuItem1_actionPerformed(e);
        }
    }
    class Frame1_jMenuHelpAbout_ActionAdapter implements ActionListener {
        Frame1 adaptee;    Frame1_jMenuHelpAbout_ActionAdapter(Frame1 adaptee) {
            this.adaptee = adaptee;
        }    public void actionPerformed(ActionEvent actionEvent) {
            adaptee.jMenuHelpAbout_actionPerformed(actionEvent);
        }
    }
      

  2.   

    package untitled1;import java.awt.BorderLayout;
    import java.awt.Frame;import javax.swing.JDialog;
    import javax.swing.JPanel;/**
     * <p>Title: </p>
     *
     * <p>Description: </p>
     *
     * <p>Copyright: Copyright (c) 2007</p>
     *
     * <p>Company: </p>
     *
     * @author not attributable
     * @version 1.0
     */
    public class Dialog1 extends JDialog {
        JPanel panel1 = new JPanel();
        BorderLayout borderLayout1 = new BorderLayout();    public Dialog1(Frame owner, String title, boolean modal) {
            super(owner, title, modal);
            try {
                setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                jbInit();
                pack();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }    public Dialog1() {
            this(new Frame(), "Dialog1", false);
        }    private void jbInit() throws Exception {
            panel1.setLayout(borderLayout1);
            getContentPane().add(panel1);
        }
    }
      

  3.   

    public void jMenuItem1_actionPerformed(ActionEvent e) {
    Dialog1 D = new Dialog1();
    D.setVisible(true);
    }
      

  4.   

    to:
    sprite_bei() ( ) 
    错误还是没有处理
      

  5.   

    Dialog1 这个类中没有参数是Frame1 的构造函数
    Dialog1 D = new Dialog1(this);这句就不对了.
      

  6.   

    to :john_sheep
    如何解决???
      

  7.   

    Dialog1 D = new Dialog1(this);无此构造函数。
      

  8.   

    改成Dialog1 D = new Dialog1();
    我这运行出来了
      

  9.   

    public void jMenuItem1_actionPerformed(ActionEvent e) {
            Dialog1 D = new Dialog1(this,"title",true);
            D.setSize(200,200);
            D.setVisible(true);
        }
      

  10.   

    Sprite_bei() ( ) 信誉:100    Blog   加为好友  2007-04-12 15:13:20  得分: 0  
     
     
       public void jMenuItem1_actionPerformed(ActionEvent e) {
    Dialog1 D = new Dialog1();
    D.setVisible(true);
    }
      
     
    -------------
    这就是解决方法
      

  11.   

    zhuokai() ( ) 信誉:100    Blog   加为好友  2007-04-12 16:35:10  得分: 0  
     
     
       public void jMenuItem1_actionPerformed(ActionEvent e) {
            Dialog1 D = new Dialog1(this,"title",true);
            D.setSize(200,200);
            D.setVisible(true);
        }
      
     
    ---------
    这个也是解决方法.具体看楼主的需要