在我的测验应用程序中切换面板不起作用。我正在使用cardlayout

时间:2015-11-05 18:12:41

标签: java swing layout-manager cardlayout

这是输出图像当我尝试按Q2或Q3面板时没有变化 enter image description here

这是gui中面板排列的图像

enter image description here

这是我正在努力的代码的一部分。请帮忙。

    public NewJFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        upperpanel = new javax.swing.JPanel();
        qu1 = new javax.swing.JButton();
        qu2 = new javax.swing.JButton();
        qu3 = new javax.swing.JButton();
        qu4 = new javax.swing.JButton();
        qu5 = new javax.swing.JButton();
        lowerpanel = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        parentpanel = new javax.swing.JPanel();
        q1 = new javax.swing.JPanel();
        question1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        q2 = new javax.swing.JPanel();
        question2 = new javax.swing.JLabel();
        jTextField7 = new javax.swing.JTextField();
        jTextField8 = new javax.swing.JTextField();
        jTextField9 = new javax.swing.JTextField();
        jTextField10 = new javax.swing.JTextField();
        jTextField11 = new javax.swing.JTextField();
        jTextField12 = new javax.swing.JTextField();
        q3 = new javax.swing.JPanel();
        question3 = new javax.swing.JLabel();
        jTextField13 = new javax.swing.JTextField();
        jTextField14 = new javax.swing.JTextField();
        jTextField15 = new javax.swing.JTextField();
        jTextField16 = new javax.swing.JTextField();
        jTextField17 = new javax.swing.JTextField();
        jTextField18 = new javax.swing.JTextField();
        q4 = new javax.swing.JPanel();
        question4 = new javax.swing.JLabel();
        jTextField19 = new javax.swing.JTextField();
        jTextField20 = new javax.swing.JTextField();
        jTextField21 = new javax.swing.JTextField();
        jTextField22 = new javax.swing.JTextField();
        jTextField23 = new javax.swing.JTextField();
        jTextField24 = new javax.swing.JTextField();
        q5 = new javax.swing.JPanel();
        question5 = new javax.swing.JLabel();
        jTextField25 = new javax.swing.JTextField();
        jTextField26 = new javax.swing.JTextField();
        jTextField27 = new javax.swing.JTextField();
        jTextField28 = new javax.swing.JTextField();
        jTextField29 = new javax.swing.JTextField();
        jTextField30 = new javax.swing.JTextField();





    private void qu1ActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        CardLayout card;
        card = (CardLayout)parentpanel.getLayout();
        card.show(parentpanel, "q1");
    }                                   

    private void qu2ActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        CardLayout card;
        card = (CardLayout)parentpanel.getLayout();
        card.show(parentpanel, "q2");
    }                                   

    private void qu3ActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        CardLayout card;
        card = (CardLayout)parentpanel.getLayout();
        card.show(parentpanel, "q3");
    }                                   

    private void qu4ActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        CardLayout card;
        card = (CardLayout)parentpanel.getLayout();
        card.show(parentpanel, "q4");
    }                                   

    private void qu5ActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
        CardLayout card;
        card = (CardLayout)parentpanel.getLayout();
        card.show(parentpanel, "q5");
    }                                   


    }

    // Variables declaration - do not modify                     

}

0 个答案:

没有答案