Skip to content
The Chat Archive
claude-sonnet-4-20250514· Anthropic LMArena Human Preference 140K

AddNewQuestion.java source code import java.sql.; import Project.ConnectionProvider;…

  1. User

    AddNewQuestion.java source code import java.sql.; import Project.ConnectionProvider; import java.awt.HeadlessException; import javax.swing.JFrame; import javax.swing.JOptionPane; /

    • Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
    • Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template */

    /** *

    • @author Hp */ public class AddNewQuestion extends javax.swing.JFrame {

      private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(AddNewQuestion.class.getName());

      /**

      • Creates new form AddNewQuestion */ public AddNewQuestion() { initComponents(); try{ Connection con=ConnectionProvider.getCon(); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select count(id) from question"); if (rs.first()) { int id=rs.getInt(1); id=id+1; String str=String.valueOf(id); jLabel5.setText(str); } else jLabel5.setText("1"); } catch (SQLException e) { JFrame jf=new JFrame(); jf.setAlwaysOnTop (true); JOptionPane.showMessageDialog(jf, e); } }

      /**

      • 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") //
        private void initComponents() {

        jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jSeparator1 = new javax.swing.JSeparator(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jLabel10 = 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(); jLabel11 = new javax.swing.JLabel(); jTextField6 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setAlwaysOnTop(true); setLocation(new java.awt.Point(150, 183)); setUndecorated(true);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/add new question.png"))); // NOI18N

        jLabel2.setFont(new java.awt.Font("Segoe UI", 1, 40)); // NOI18N jLabel2.setText("ADD NEW QUESTION");

        jLabel4.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N jLabel4.setText("Question ID:");

        jLabel5.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N jLabel5.setForeground(new java.awt.Color(255, 0, 0)); jLabel5.setText("00");

        jLabel6.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N jLabel6.setForeground(new java.awt.Color(0, 51, 255)); jLabel6.setText("Question:");

        jLabel7.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N jLabel7.setText("Option1:");

        jLabel8.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N jLabel8.setText("Option2:");

        jLabel9.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N jLabel9.setText("Option3:");

        jLabel10.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N jLabel10.setText("Option4:");

        jTextField1.setBackground(new java.awt.Color(164, 170, 249)); jTextField1.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N

        jTextField2.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N

        jTextField3.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N

        jTextField4.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N

        jTextField5.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N

        jLabel11.setBackground(new java.awt.Color(153, 153, 255)); jLabel11.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N jLabel11.setForeground(new java.awt.Color(0, 204, 0)); jLabel11.setText("Answer");

        jTextField6.setBackground(new java.awt.Color(170, 245, 170)); jTextField6.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Close.png"))); // NOI18N jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } });

        jButton2.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/save.png"))); // NOI18N jButton2.setText("Save"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } });

        jButton3.setFont(new java.awt.Font("Segoe UI", 1, 20)); // NOI18N jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/clear.png"))); // NOI18N jButton3.setText("Clear"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(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(12, 12, 12) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton1) .addGap(18, 18, 18)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jSeparator1) .addContainerGap()) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(129, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel4) .addGap(18, 18, 18) .addComponent(jLabel5)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel10) .addComponent(jLabel9) .addComponent(jLabel8) .addComponent(jLabel7) .addComponent(jLabel6) .addComponent(jLabel11)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jTextField1) .addComponent(jTextField2) .addComponent(jTextField5) .addComponent(jTextField3) .addComponent(jTextField4) .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 700, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGap(119, 119, 119)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jButton1) .addGap(18, 18, 18))) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(jLabel5)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel9) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel10) .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel11) .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton2) .addComponent(jButton3)) .addGap(25, 25, 25)) );

        pack(); }//

      private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
      // TODO add your handling code here:

       String id = jLabel5.getText();
      

    String name = jTextField1.getText(); String opt1 = jTextField2.getText(); String opt2 = jTextField3.getText(); String opt3 = jTextField4.getText(); String opt4 = jTextField5.getText(); String answer = jTextField6.getText();

    try { Connection con = ConnectionProvider.getCon(); PreparedStatement ps = con.prepareStatement( "INSERT INTO question VALUES (?, ?, ?, ?, ?, ?, ?)" ); ps.setString(1, id); ps.setString(2, name); ps.setString(3, opt1); ps.setString(4, opt2); ps.setString(5, opt3); ps.setString(6, opt4); ps.setString(7, answer); ps.executeUpdate(); JFrame jf = new JFrame(); jf.setAlwaysOnTop(true); JOptionPane.showMessageDialog(jf, "Successfully Updated!"); jf.dispose();

    this.setVisible(false);
    new AddNewQuestion().setVisible(true);
    

    } catch (HeadlessException | SQLException e) { JFrame jf = new JFrame(); jf.setAlwaysOnTop(true); JOptionPane.showMessageDialog(jf, e); }

    }                                        
    
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        jTextField1.setText("");
        jTextField2.setText("");
        jTextField3.setText("");
        jTextField4.setText("");
        jTextField5.setText("");
        jTextField6.setText("");
    }                                        
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        
        adminHome.open=0;
        setVisible(false);
    }                                        
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) {
            logger.log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
    
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(() -> new AddNewQuestion().setVisible(true));
    }
    
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    // End of variables declaration                   
    

    }

    adminHome.java source code import javax.swing.JFrame; import javax.swing.JOptionPane; /*

    • Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
    • Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template */

    /** *

    • @author Hp */ public class adminHome extends javax.swing.JFrame { public static int open=0;
      private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(adminHome.class.getName());

      /**

      • Creates new form adminHome */ public adminHome() { 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") //
        private void initComponents() {

        jMenuBar2 = new javax.swing.JMenuBar(); jMenu8 = new javax.swing.JMenu(); jMenu9 = new javax.swing.JMenu(); jMenu10 = new javax.swing.JMenu(); jMenu11 = new javax.swing.JMenu(); jMenu12 = new javax.swing.JMenu(); jMenu13 = new javax.swing.JMenu(); jMenu14 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setUndecorated(true);

        jMenuBar2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Navigation Bar", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 1, 36), new java.awt.Color(0, 153, 153))); // NOI18N

        jMenu8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Document-New-48x48.png"))); // NOI18N jMenu8.setText("Add New Question"); jMenu8.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N jMenu8.setMargin(new java.awt.Insets(0, 5, 0, 30)); jMenu8.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jMenu8MouseClicked(evt); } }); jMenuBar2.add(jMenu8);

        jMenu9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Update Question.png"))); // NOI18N jMenu9.setText("Update Question"); jMenu9.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N jMenu9.setMargin(new java.awt.Insets(0, 5, 0, 30)); jMenuBar2.add(jMenu9);

        jMenu10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/all questions.png"))); // NOI18N jMenu10.setText("All Question"); jMenu10.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N jMenu10.setMargin(new java.awt.Insets(0, 5, 0, 30)); jMenuBar2.add(jMenu10);

        jMenu11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/delete Question.png"))); // NOI18N jMenu11.setText("Delete Question"); jMenu11.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N jMenu11.setMargin(new java.awt.Insets(0, 5, 0, 30)); jMenuBar2.add(jMenu11);

        jMenu12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/all student result.png"))); // NOI18N jMenu12.setText("All Student Result"); jMenu12.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N jMenu12.setMargin(new java.awt.Insets(0, 5, 0, 30)); jMenuBar2.add(jMenu12);

        jMenu13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Logout.png"))); // NOI18N jMenu13.setText("Logout"); jMenu13.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N jMenu13.setMargin(new java.awt.Insets(0, 5, 0, 30)); jMenu13.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jMenu13MouseClicked(evt); } }); jMenuBar2.add(jMenu13);

        jMenu14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Close.png"))); // NOI18N jMenu14.setText("Exit"); jMenu14.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N jMenu14.setMargin(new java.awt.Insets(0, 5, 0, 30)); jMenu14.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jMenu14MouseClicked(evt); } }); jMenuBar2.add(jMenu14);

        setJMenuBar(jMenuBar2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 1366, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 647, Short.MAX_VALUE) );

        pack(); }//

      private void jMenu13MouseClicked(java.awt.event.MouseEvent evt) {
      // TODO add your handling code here: JFrame jf=new JFrame(); jf.setAlwaysOnTop(true); int a=JOptionPane.showConfirmDialog(jf, "Are you sure you want to Logout", "select", JOptionPane.YES_NO_OPTION); if (a==0) { setVisible(false); new loginAdmin().setVisible(true); } }

      private void jMenu14MouseClicked(java.awt.event.MouseEvent evt) {
      // TODO add your handling code here: JFrame jf=new JFrame(); jf.setAlwaysOnTop(true); int a=JOptionPane.showConfirmDialog(jf, "Are you sure you want to Exit?", "select", JOptionPane.YES_NO_OPTION); if (a==0) { System.exit(0); } }

      private void jMenu8MouseClicked(java.awt.event.MouseEvent evt) {
      // TODO add your handling code here: if (open == 0) { AddNewQuestion form = new AddNewQuestion(); form.setLocationRelativeTo(this); // Center relative to admin home form.setVisible(true); form.toFront(); // Bring to front open = 1; } else { JOptionPane.showMessageDialog(this, "A form is already open."); } }

      /**

      • @param args the command line arguments / public static void main(String args[]) { / Set the Nimbus look and feel / // / If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

        • For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) { logger.log(java.util.logging.Level.SEVERE, null, ex); } //

        /* Create and display the form */ java.awt.EventQueue.invokeLater(() -> new adminHome().setVisible(true)); }

      // Variables declaration - do not modify
      private javax.swing.JMenu jMenu10; private javax.swing.JMenu jMenu11; private javax.swing.JMenu jMenu12; private javax.swing.JMenu jMenu13; private javax.swing.JMenu jMenu14; private javax.swing.JMenu jMenu8; private javax.swing.JMenu jMenu9; private javax.swing.JMenuBar jMenuBar2; // End of variables declaration
      }

    Connection provider.java /*

    • Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
    • Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package Project; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException;

    /** *

    • @author Hp */

    public class ConnectionProvider { public static Connection getCon() { try { Class.forName("com.mysql.cj.jdbc.Driver"); // Updated driver class name Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/gems", "root", "123456"); return con; } catch (ClassNotFoundException | SQLException e) {

            return null;
        }
    }
    

    }

    now why isn't that when jMenu8MouseClicked is clicked its not opening AddNewQuestion

  2. Assistant

    Looking at your code, the issue is likely that the AddNewQuestion form is opening but not visible due to positioning or layering problems. Here are the main issues and solutions:

    Issues Identified:

    1. Fixed positioning in AddNewQuestion: The form has setLocation(new java.awt.Point(150, 183)) which might position it off-screen or behind other windows.

    2. Window management: The adminHome window is undecorated, which can cause focus and layering issues.

    Solutions:

    Option 1: Fix the positioning (Recommended)

    Modify the jMenu8MouseClicked method in adminHome.java:

    private void jMenu8MouseClicked(java.awt.event.MouseEvent evt) {                                    
        if (open == 0) {
            AddNewQuestion form = new AddNewQuestion();
            form.setLocationRelativeTo(this); // This will override the fixed position
            form.setVisible(true);
            form.toFront();
            form.requestFocus(); // Add this to ensure focus
            open = 1;
        } else {
            JOptionPane.showMessageDialog(this, "A form is already open.");
        }
    }
    

    Option 2: Remove fixed positioning from AddNewQuestion

    In AddNewQuestion.java, comment out or remove this line from initComponents():

    // setLocation(new java.awt.Point(150, 183)); // Remove or comment this line
    

    Option 3: Add debugging to verify the form is created

    Add some debug output to see what's happening:

    private void jMenu8MouseClicked(java.awt.event.MouseEvent evt) {                                    
        System.out.println("Menu clicked, open = " + open); // Debug line
        if (open == 0) {
            AddNewQuestion form = new AddNewQuestion();
            System.out.println("Form created"); // Debug line
            form.setLocationRelativeTo(this);
            form.setVisible(true);
            System.out.println("Form set visible"); // Debug line
            form.toFront();
            form.requestFocus();
            open = 1;
        } else {
            JOptionPane.showMessageDialog(this, "A form is already open.");
        }
    }
    

    Additional Recommendations:

    1. Make adminHome visible: Ensure your adminHome window is properly displayed and has focus when you click the menu.

    2. Check the open variable: Make sure open is being reset to 0 when forms are closed. I see you have adminHome.open=0; in the close button, which is correct.

    3. Consider using JDialog instead of JFrame: For modal dialogs like this, JDialog might be more appropriate than JFrame.

    Try Option 1 first, as it's the most likely solution to your problem. The fixed positioning combined with the undecorated parent window is probably causing the visibility issue.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.