Hi,
I need to make the frame invisible on action event in swings.
I have the following code:
public class sample_pgm extends JFrame{
public void sample()
{
JFrame jf = new JFrame("Sample");
JPanel panel = new JPanel();
Container c = jf.getContentPane();
JButton subscribe_button = new JButton("submit");
panel.add(subscribe_button);
subscribe_button.addActionListener(new MyButtonListener(this));
String[] fields ={"Name","Depart"};
String[][] data ={{"Name","Depart"},{"asdsdf","assdf"}};
JTable table = new JTable(data, fields);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setPreferredSize(new Dimension(500, 150));
panel.add(scrollPane);
c.add(panel);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.pack();
jf.setVisible(true);
}
public static void main(String args[])
{
sample_pgm s =new sample_pgm();
s.sample();
}
private class MyButtonListener implements ActionListener
{
private JFrame parentComponent;
MyButtonListener(JFrame parentComponent)
{
this.parentComponent=parentComponent;
}
public void actionPerformed(ActionEvent e) {
parentComponent.setVisible(false);
}
}
}
when i tried above code.. Frame is still visible.. How can i correct taht.. help pl..
-Thanks & Regards,
Hamsa