从JPanel调用JInternalframe

时间:2017-01-05 20:27:12

标签: java swing

我想从Panel调用JInternalframe。

我使用main方法和JDesktopPane

获得了一个jframeJFrame

我有一个JInternalFrame NewJInternalFrame,我称之为JPanel NewJPanel

现在我想从我的JPanel NewJPanel调用另一个JInternalFrame NewJInternalFrame1并将其添加到我的JDeskptopPane dp

public class JFrame extends javax.swing.JFrame {

    /**
     * Creates new form JFrame
     */
    public JFrame() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {     

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        NewJInternalFrame s = new NewJInternalFrame();
        s.setVisible(true);
        this.jDesktopPane1.add(s);
        // TODO add your handling code here:
    }                                          

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
       java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JFrame().setVisible(true);
            }
        });
    }

    // Variables declaration                    
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    // End of variables declaration                   
}

公共类NewJInternalFrame扩展了javax.swing.JInternalFrame {

public NewJInternalFrame() {
    initComponents();
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        NewJPanel up = new NewJPanel();
        jTabbedPane1.add(up);

    }                                        

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration                   
}

public class NewJInternalFrame1 extends javax.swing.JInternalFrame {


    public NewJInternalFrame1() {
        initComponents();
    }



 public class NewJPanel extends javax.swing.JPanel {

        /**
         * Creates new form NewJPanel
         */
        public NewJPanel() {
            initComponents();
        }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            //call NewJInteralFrame1

            NewJInternalFrame1 f1 = new NewJInternalFrame1();
                JDesktopPane desktopPane = this.getDesktopPane();
                desktopPane.add(f1);
                f1.setVisible(true);
        }                                        

        // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
        // End of variables declaration                   
    }

我尝试了以下内容:

public class Jp1 extends javax.swing.JPanel {
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            Jf2 f = new Jf2();
            JDesktopPane desktopPane = this.getDesktopPane();
            desktopPane.add(f);
            me.setVisible(true);

        }   

但这不起作用,因为它说我应该创建方法getDesktopPane()

有人可以帮帮我吗?

0 个答案:

没有答案