Calling Container object's setVisible(boolean) method

Hi All!

I have a noobie question regarding swing.

I want to know how to call the JFrame Object's setVisible(boolean) method inside JButton object's addActionListener() method (when JButton object is a component under the JFrame object).

Code:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class Sample extrends JFrame{

public Sample(){

...

btnCancel.setBounds (125,90,100,25);

btnCancel.addActionListener (new ActionListener(){

public void actionPerformed(ActionEvent ae){

//Code for calling the class setVisible(boolean) method

//since this.setVisible(false) wont work

//because 'this' might point to btnCancel object not

//JFrame

}

});

...

}

}

[844 byte] By [khickyphutza] at [2007-11-27 8:15:48]
# 1
Don't forget to use the "Code Formatting Tags", see http://forum.java.sun.com/help.jspa?sec=formatting, so the posted code retains its original formatting.SwingUtilities.windowForComponent(...);
camickra at 2007-7-12 20:00:38 > top of Java-index,Desktop,Core GUI APIs...
# 2

Ok thanks for the info... but any idea on this problem I am facing? I know this is just simple for you guys.

I have this Cancel JButton that will close the JFrame object when it will be clicked. Any idea how to call the setVisible(boolean) method of the JFrame object inside JButton object's addActionListener() method?

khickyphutza at 2007-7-12 20:00:38 > top of Java-index,Desktop,Core GUI APIs...
# 3
> Ok thanks for the info... but any idea on this problem I am facing?That was the answer.The ActionEvent will tell you which button you clicked on so you use the method I gave you to find the window the button was added to. Once you know that you can hide the window.
camickra at 2007-7-12 20:00:38 > top of Java-index,Desktop,Core GUI APIs...
# 4
Hehehe thanks a lot dude... you reply fast hehe... you might be online 24/7 hehehe
khickyphutza at 2007-7-12 20:00:38 > top of Java-index,Desktop,Core GUI APIs...