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.getContentPa ne();
JButton subscribe_butto n = new JButton("submit ");
panel.add(subsc ribe_button);
subscribe_butto n.addActionList ener(new MyButtonListene r(this));
String[] fields ={"Name","Depar t"};
String[][] data ={{"Name","Depa rt"},{"asdsdf", "assdf"}};
JTable table = new JTable(data, fields);
JScrollPane scrollPane = new JScrollPane(tab le);
scrollPane.setP referredSize(ne w Dimension(500, 150));
panel.add(scrol lPane);
c.add(panel);
jf.setDefaultCl oseOperation(JF rame.EXIT_ON_CL OSE);
jf.pack();
jf.setVisible(t rue);
}
public static void main(String args[])
{
sample_pgm s =new sample_pgm();
s.sample();
}
private class MyButtonListene r implements ActionListener
{
private JFrame parentComponent ;
MyButtonListene r(JFrame parentComponent )
{
this.parentComp onent=parentCom ponent;
}
public void actionPerformed (ActionEvent e) {
parentComponent .setVisible(fal se);
}
}
}
when i tried above code.. Frame is still visible.. How can i correct taht.. help pl..
-Thanks & Regards,
Hamsa
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.getContentPa ne();
JButton subscribe_butto n = new JButton("submit ");
panel.add(subsc ribe_button);
subscribe_butto n.addActionList ener(new MyButtonListene r(this));
String[] fields ={"Name","Depar t"};
String[][] data ={{"Name","Depa rt"},{"asdsdf", "assdf"}};
JTable table = new JTable(data, fields);
JScrollPane scrollPane = new JScrollPane(tab le);
scrollPane.setP referredSize(ne w Dimension(500, 150));
panel.add(scrol lPane);
c.add(panel);
jf.setDefaultCl oseOperation(JF rame.EXIT_ON_CL OSE);
jf.pack();
jf.setVisible(t rue);
}
public static void main(String args[])
{
sample_pgm s =new sample_pgm();
s.sample();
}
private class MyButtonListene r implements ActionListener
{
private JFrame parentComponent ;
MyButtonListene r(JFrame parentComponent )
{
this.parentComp onent=parentCom ponent;
}
public void actionPerformed (ActionEvent e) {
parentComponent .setVisible(fal se);
}
}
}
when i tried above code.. Frame is still visible.. How can i correct taht.. help pl..
-Thanks & Regards,
Hamsa
Comment