0

I have made a button By default invisible by customizing code. But now my problem is I cant make the button visible! The thing I want is,that when user LOG IN means the LOG OUT button should be visible. How can i do it using netbeans? can any1 help me? I m new in JAVA GUI. What condition should i add here?

 JLabel j1;

public NewJFrame() {
    initComponents();
}

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

    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jButton4 = new javax.swing.JButton();
    jLabel5 = new javax.swing.JLabel();
    jLabel1 = new javax.swing.JLabel();
    jComboBox1 = new javax.swing.JComboBox();
    jButton1 = new javax.swing.JButton();
    jTextField3 = new javax.swing.JTextField();
    jButton2 = new javax.swing.JButton();
    jPasswordField1 = new javax.swing.JPasswordField();
    jButton3 = new javax.swing.JButton();
    jButton5 = new javax.swing.JButton();
    jLabel6 = new javax.swing.JLabel();
    jComboBox2 = new javax.swing.JComboBox();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    jTextField2 = new javax.swing.JTextField();
    jComboBox3 = new javax.swing.JComboBox();
    jLabel9 = new javax.swing.JLabel();
    jLabel10 = new javax.swing.JLabel();
    jButton6 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jLabel2.setFont(new java.awt.Font("Segoe UI", 1, 24)); // NOI18N
    jLabel2.setForeground(new java.awt.Color(102, 255, 0));
    jLabel2.setText("EMAIL");

    jLabel3.setFont(new java.awt.Font("Segoe UI", 1, 24)); // NOI18N
    jLabel3.setForeground(new java.awt.Color(102, 255, 0));
    jLabel3.setText("PASSWORD");

    jTextField1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 153), 2, true));
    jTextField1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jTextField1ActionPerformed(evt);
        }
    });

    jButton4.setBackground(new java.awt.Color(0, 153, 255));
    jButton4.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N
    jButton4.setText("Log In");
    jButton4.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, null, new java.awt.Color(0, 153, 255), null, null)));
    jButton4.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton4ActionPerformed(evt);
        }
    });

    jLabel5.setBackground(new java.awt.Color(255, 153, 102));
    jLabel5.setFont(new java.awt.Font("Rockwell Extra Bold", 3, 24)); // NOI18N
    jLabel5.setForeground(new java.awt.Color(255, 0, 204));
    jLabel5.setText("SELECT TYPE");

    jLabel1.setBackground(new java.awt.Color(153, 102, 255));
    jLabel1.setFont(new java.awt.Font("Bookman Old Style", 3, 48)); // NOI18N
    jLabel1.setForeground(new java.awt.Color(255, 0, 204));
    jLabel1.setText("SHOPPERS BAY...");
    jLabel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, null, new java.awt.Color(255, 102, 102), new java.awt.Color(255, 255, 102), null));
    jLabel1.setIconTextGap(2);

    jComboBox1.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
    jComboBox1.setForeground(new java.awt.Color(0, 0, 51));
    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CLOTHES", "ACCESSORIES", "SHOES" }));
    jComboBox1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createCompoundBorder(), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));

    jButton1.setBackground(new java.awt.Color(0, 153, 255));
    jButton1.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
    jButton1.setText("OK");
    jButton1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(0, 153, 255), new java.awt.Color(0, 153, 255), null, null)));
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    jTextField3.setForeground(new java.awt.Color(153, 153, 153));
    jTextField3.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 255), 1, true));
    jTextField3.setDisabledTextColor(new java.awt.Color(0, 0, 0));
    jTextField3.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jTextField3ActionPerformed(evt);
        }
    });

    jButton2.setBackground(new java.awt.Color(255, 51, 51));
    jButton2.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
    jButton2.setText("SEARCH");
    jButton2.setBorder(javax.swing.BorderFactory.createCompoundBorder(null, javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
    jButton2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton2ActionPerformed(evt);
        }
    });

    jPasswordField1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 153), 2, true));

    jButton3.setBackground(new java.awt.Color(0, 153, 255));
    jButton3.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N
    jButton3.setText("Register");
    jButton3.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, null, new java.awt.Color(0, 153, 255), null, null)));
    jButton3.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton3ActionPerformed(evt);
        }
    });

    jButton5.setFont(new java.awt.Font("Stencil", 3, 14)); // NOI18N
    jButton5.setForeground(new java.awt.Color(204, 0, 0));
    jButton5.setText("ACCOUNTS");
    jButton5.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, null, new java.awt.Color(102, 204, 0), null, new java.awt.Color(102, 51, 0)));
    jButton5.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton5ActionPerformed(evt);
        }
    });

    jLabel6.setFont(new java.awt.Font("Tahoma", 3, 24)); // NOI18N
    jLabel6.setForeground(new java.awt.Color(255, 0, 204));
    jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel6.setText("New User?");

    jComboBox2.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
    jComboBox2.setForeground(new java.awt.Color(0, 0, 51));
    jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "VISITOR", "ACCOUNTANT", "ADMINISTRATOR" }));
    jComboBox2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, null, new java.awt.Color(102, 255, 0), null, null));
    jComboBox2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jComboBox2ActionPerformed(evt);
        }
    });

    jLabel7.setFont(new java.awt.Font("SimSun-ExtB", 1, 11)); // NOI18N
    jLabel7.setForeground(new java.awt.Color(102, 255, 0));
    jLabel7.setText("PRICE:");

    jLabel8.setText("to");

    jTextField2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 255), 1, true));

    jComboBox3.setBackground(new java.awt.Color(255, 204, 204));
    jComboBox3.setFont(new java.awt.Font("Stencil", 1, 12)); // NOI18N
    jComboBox3.setForeground(new java.awt.Color(51, 51, 255));
    jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CLOTHES", "ACCESSORIES", "SHOES" }));
    jComboBox3.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(255, 0, 204)));

    jLabel9.setFont(new java.awt.Font("SimSun-ExtB", 1, 12)); // NOI18N
    jLabel9.setForeground(new java.awt.Color(102, 255, 0));
    jLabel9.setText("CATEGORY:");

    jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/finalproject/Collages - Copy1.png"))); // NOI18N

    jButton6.setText("LOGOUT");
    jButton6.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton6ActionPerformed(evt);
        }
    });
    jButton6.setVisible(false);
    if(jComboBox2.getSelectedItem()=="ADMINISTRATOR")
    jButton6.setVisible(true);

    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(30, 30, 30)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel1)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(59, 59, 59)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(69, 69, 69)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(107, 107, 107)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jButton6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(58, 58, 58)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(4, 4, 4)
                            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(10, 10, 10)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(10, 10, 10)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGap(79, 79, 79)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(184, 184, 184))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(168, 168, 168))))))
                .addComponent(jLabel10))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(jLabel3)
                .addComponent(jLabel2))
            .addGap(18, 18, 18)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(67, 67, 67))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(33, 33, 33)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel9)
                            .addGap(14, 14, 14)
                            .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(1, 1, 1)
                            .addComponent(jLabel7)
                            .addGap(14, 14, 14)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(28, 28, 28)
                            .addComponent(jLabel8))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(27, 27, 27)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(24, 24, 24)
                            .addComponent(jButton2)))
                    .addGap(33, 33, 33))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
            .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(3, 3, 3)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2))
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)))
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(20, 20, 20)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(80, 80, 80))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))))
            .addGap(7, 7, 7)
            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE))
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGap(48, 48, 48)))
            .addComponent(jButton5))
    );

    pack();
}// </editor-fold>                        

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

        Connection conn=null;
    try{
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        conn =DriverManager.getConnection(DB_URL, USER, PASS);
        Statement stmt=conn.createStatement();

        String S1 = jTextField1.getText();
        String S2 = jPasswordField1.getText().toString();
        String S3=jComboBox2.getSelectedItem().toString();
       // System.out.println("User: "+userName + " Password: "+ passWord);

        // if user name is blank, warning message shown
        if(S1.isEmpty() || S1 == null){
            JOptionPane.showMessageDialog(null, "Please insert a valid user name", "Warning", JOptionPane.WARNING_MESSAGE);
            return;
        }
        // if password is blank, warning message shown
        if(S2.isEmpty() || S2 == null){
            JOptionPane.showMessageDialog(null, "Password field is empty", "Warning", JOptionPane.WARNING_MESSAGE);
            return;
        }

        int flag=0;
        String sql;
        sql="SELECT * from member where EMAIL='"+S1+"'";
        ResultSet rs=stmt.executeQuery(sql);
        //System.out.println(rs.next());
        String uname="",pw="",category="";
        while(rs.next()){                       
        uname=rs.getString("EMAIL");
        pw=rs.getString("PASSWORD");
        category=rs.getString("CATEGORY");

        if(uname.matches(S1) && pw.equals(S2)==true && category.matches(S3))
        {
            flag=1;
            /*setVisible(false);
    Congrats J7=new Congrats();
    J7.getContentPane().setBackground(Color.green);
    J7.setVisible(true); */
          if(jComboBox2.getSelectedItem()=="VISITOR")
    {
        setVisible(false);
    NewJFrame f1=new NewJFrame();
    f1.setVisible(true);
    jButton6.setVisible(true);
    }
    else if(jComboBox2.getSelectedItem()=="ACCOUNTANT")
    {
         setVisible(false);
    inter4 f=new inter4();
    f.setVisible(true);
    }
    else if(jComboBox2.getSelectedItem()=="ADMINISTRATOR")
    {
      setVisible(false);
    NewJFrame f1=new NewJFrame();
    f1.setVisible(true);
    }
         }
        } 
        if(flag==0)
            JOptionPane.showMessageDialog(null,"login failed");      
        stmt.close();
        conn.close();
        }
    catch(SQLException ss){
      ss.printStackTrace(); 
}   

}                                        

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
    setVisible(false);
    NewJFrame21 fF=new NewJFrame21();
    fF.getContentPane().setBackground(Color.magenta);
    fF.setVisible(true);
}                                        

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
    setVisible(false);
    inter4 J1=new inter4();
    J1.getContentPane().setBackground(Color.green);
    J1.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.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JComboBox jComboBox2;
private javax.swing.JComboBox jComboBox3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
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.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration                   

private ImageIcon format=null;
}
10
  • 3
    Java and Javascript? Ooh man! I removed Javascript tag. Anyway post the code. Commented Mar 23, 2014 at 21:38
  • Java != JavaScript. Until you clarified what language you are using, post some code and explain your problem better, we cannot help you. Commented Mar 23, 2014 at 21:39
  • I just learned now netbeans can be used for Javascript too.. maybe i removed the wrong tag? Commented Mar 23, 2014 at 21:40
  • do you want to develop a website or an computer application? For the first one you use javascript and HTML, for the second one you use Java.
    – alpham8
    Commented Mar 23, 2014 at 21:43
  • 1
    @MarcoAcierno , all good : ) Even it the question was tagged machinecode nobody could help without seeing any code. Commented Mar 23, 2014 at 21:43

1 Answer 1

0

Being new in Java GUI I believe that is better to write some GUI code by hand, just to see how things work. When you understand the concept of swing, you can move on to a GUI designer to make things easier and faster. But without (deep) understanding of things like Event Handling, Layout Managers, and such things you can't be sure about "how" to implement what you want to implement (and make it appear on screen and interact)

So what you want is a button getting visible when you push another button (the LOG IN one). This has to be done with an ActionListener to the LOG IN button. So, you have to state to the compiler that this class will have some Action Events ("action" events are the cases of button clicks, "key" events are the cases of keys pressed, etc).

So you write in your class definition:

class GUIExample implements ActionListener{

Now you can define the buttons (I will define few of them). Note: always declare button (and other component) names as class fields (not in the method that instantiates them) so you can refer to them inside all the class methods.

JButton logIn, logOut;
JFrame frame;    //the application main frame

That should do it! Now lets make a constructor!

GUIExample(){
    frame = new JFrame("GUI Example in Swing");    //frame's head text
    logIn = new JButton("LOG IN");
    logOut = new JButton("LOG OUT");
    frame.setSize(300,400);
    frame.setVisible(true);
    frame.add(logIn);
    logIn.setVisible(true);
    frame.add(logOut);
    logOut.setVisible(false);        //The LOG OUT is invisible now!
    logIn.addActionListener(this);        //this tells the JVM to keep an eye on this
                                          // button and run the actionPerformed method
                                          // if it gets pushed!
}

Now you have to tell the JVM "what to do" if the button LOG IN is pressed!

    public void actionPerformed(ActionEvent e){

        JButton src = (JButton) e.getSource()    //get the objectthat triggered the event
        if (src.equals(logIn))        //if the source is the LOG IN button (in our case it is the only thing that can trigger an event)
            logOut.setVisible(true);    ///finally! make the LOG OUT visible!
    }

This should do it! Now call the constructor via the main:

public static void main (String args[]){
    new GUIExample();
}

This is it! To run this example don't forget to import Swing:

 import javax.swing.*;

and the event package:

 import java.awt.event.*;

Hope I helped!

3
  • There just might be one problem with the action listener. What if the user clicks login and actually the details are wrong, I think the button becomes visible regardless.
    – Alex Goja
    Commented Mar 23, 2014 at 22:45
  • It sure does. But I made just an example. In the real application the actionPerformed calls a login-Verification method that connects to SQL DB or any other source of info to make the login. if it returns true, the LOG OUT gets visible (and LOG IN gets invisible too) Commented Mar 23, 2014 at 22:49
  • The point was a basic swing mechanics understanding. If the OP understands the concept he/she can surely adapt it to his/her needs! Commented Mar 23, 2014 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.