hello,
i`m having a problem with if and else, as you can see in the code in below the if and else is working for the first qustion, but how i can change it if i want to move to the next qustion ?
public class easy extends javax.swing.JFrame { public easy() { initComponents(); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { buttonGroup1 = new javax.swing.ButtonGroup(); buttonGroup2 = new javax.swing.ButtonGroup(); jLabel1 = new javax.swing.JLabel(); jRadioButton1 = new javax.swing.JRadioButton(); jRadioButton2 = new javax.swing.JRadioButton(); jRadioButton3 = new javax.swing.JRadioButton(); jRadioButton4 = new javax.swing.JRadioButton(); jLabel2 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(java.awt.event.WindowEvent evt) { formWindowOpened(evt); } }); jButton1.setText("Submit"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("Next"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(19, 19, 19) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 221, Short.MAX_VALUE) .addComponent(jButton2) .addGap(40, 40, 40)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jRadioButton2) .addComponent(jRadioButton1) .addComponent(jRadioButton3) .addComponent(jRadioButton4)) .addContainerGap(360, Short.MAX_VALUE)))) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addContainerGap(390, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(194, Short.MAX_VALUE) .addComponent(jLabel2) .addGap(206, 206, 206)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(20, 20, 20) .addComponent(jLabel1) .addGap(18, 18, 18) .addComponent(jRadioButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jRadioButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jRadioButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jRadioButton4) .addGap(76, 76, 76) .addComponent(jLabel2) .addGap(27, 27, 27) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jButton2)) .addContainerGap(52, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void formWindowOpened(java.awt.event.WindowEvent evt) { jLabel1.setText("whats my name?"); jRadioButton1.setText("aziz"); jRadioButton2.setText("fahad"); jRadioButton3.setText("Abdulla"); jRadioButton4.setText("Khaled"); buttonGroup1.add(jRadioButton1); buttonGroup1.add(jRadioButton2); buttonGroup1.add(jRadioButton3); buttonGroup1.add(jRadioButton4); buttonGroup2.add(jRadioButton1); buttonGroup2.add(jRadioButton2); buttonGroup2.add(jRadioButton3); buttonGroup2.add(jRadioButton4); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { if (jRadioButton1.isSelected()) { jLabel2.setText("right");} else jLabel2.setText("wrong"); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { jLabel2.setText(null); jLabel1.setText("how old am I"); jRadioButton1.setText("15"); jRadioButton2.setText("16"); jRadioButton3.setText("17"); jRadioButton4.setText("18"); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new easy().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.ButtonGroup buttonGroup1; private javax.swing.ButtonGroup buttonGroup2; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JRadioButton jRadioButton1; private javax.swing.JRadioButton jRadioButton2; private javax.swing.JRadioButton jRadioButton3; private javax.swing.JRadioButton jRadioButton4; // End of variables declaration }