When I m trying to call panel2 inside actionPerformed method, I m getting nullpointerexception. Plz help me in getting out of this silly prblm.
public class PanelEventTest implements ActionListener {
/**
* @param args
*/
JFrame frame;
JPanel panel1, panel2;
String[] list = {"Sachin","Tarun","Vipin"};
JList jlist;
JButton next;
void originalFrame()
{
frame = new JFrame();
frame.setSize(500, 300);
frame.setVisible(true);
frame.setLayout(new FlowLayout());
frame.add(panel1());
frame.add(panel2());
}
JPanel panel1()
{
panel1 = new JPanel();
next = new JButton("Next");
next.addActionListener(new PanelEventTest());
panel1.add(next);
return panel1;
}
JPanel panel2()
{
panel2 = new JPanel();
jlist = new JList(list);
panel2.add(jlist);
panel2.add(new JLabel("Test"));
return panel2;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new PanelEventTest().originalFrame();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getActionCommand() == "Next")
{
panel2.removeAll();
}
}
}
action event is not attached with panel2, is that a reason behind this exception?