I'm trying to make a gui for connecting to a database and updating/deleting files/searching tables. I wanted to have all the buttons on the left side then use the rest of the application for the option they choose. EX: they clicked "Search by name" it will show a field on the right side with a name box, a search button, and underneath a table like box that will hold all the records in the result.
When i thoguht of how i could do this ifigure i can make a panel cooresponding to the buttons they pressed and set the visibility to false, then when a buttons pressed the qpanel that goes for that button will have visibility set to true.
The problem i'm having is making a panel inside contentPane and havig it Not visible and changing it to visible. The code i have now is:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.*;
public class GUI extends JFrame implements ActionListener{
public static final int WIDTH = 800;
public static final int HEIGHT = 600;
public GUI(){
setSize(WIDTH, HEIGHT);
WindowDestroyer listener = new WindowDestroyer( );
addWindowListener(listener);
Container contentPane = getContentPane();
contentPane.setBackground(Color.white);
contentPane.setLayout(new BorderLayout());
JPanel buttonpanel = new JPanel();
buttonpanel.setLayout(new BoxLayout(buttonpanel, BoxLayout.PAGE_AXIS));
buttonpanel.setBackground(Color.white);
JButton custid = new JButton("CustID");
custid.addActionListener(this);
buttonpanel.add(custid);
JButton fname = new JButton("First Name");
fname.addActionListener(this);
buttonpanel.add(fname);
JButton lname = new JButton("Last Name");
lname.addActionListener(this);
buttonpanel.add(lname);
JButton phone = new JButton("Phone");
phone.addActionListener(this);
buttonpanel.add(phone);
JButton email = new JButton("E-Mail");
email.addActionListener(this);
buttonpanel.add(email);
contentPane.add(buttonpanel, BorderLayout.WEST);
JPanel
testing = new JPanel();
testing.setLayout(new BoxLayout(testing, BoxLayout.PAGE_AXIS));
testing.setBackground(Color.white);
JButton TEST1 = new JButton("THIS");
TEST1.addActionListener(this);
testing.add(TEST1);
JButton TEST2 = new JButton("IS");
TEST2.addActionListener(this);
testing.add(TEST2);
JButton TEST3 = new JButton("TESTING");
TEST3.addActionListener(this);
testing.add(TEST3);
contentPane.add(testing, BorderLayout.EAST);
}
public void actionPerformed(ActionEvent e)
{
String actionCommand = e.getActionCommand( );
Container contentPane = getContentPane( );
if (actionCommand.equals("CustID"))
contentPane.setBackground(Color.BLUE);
else if (actionCommand.equals("First Name"))
contentPane.setBackground(Color.GRAY);
else if (actionCommand.equals("Last Name"))
contentPane.setBackground(Color.GREEN);
else if (actionCommand.equals("Phone"))
contentPane.setBackground(Color.RED);
else if (actionCommand.equals("E-Mail"))
/*THIS IS WHERE THE ERROR IS testing cannot be resolved*/ testing.setVisible(true);
else
System.out.println("Error in button interface.");
}
}
Near the bottom you can see where its erroring, testing.setVisible(true);
How would i access the visibility of testing? or am i doing this all wrong and there's another way to make all of the happen besides making everything invisible?