public class MyClass extends JFrame implements ActionListener {
public MyClass() {
super("Frame Window");
setLayout(new FlowLayout());
setSize(700, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton setInv = new JButton("set invisible");
setInv.setVisible(true);
setInv.setPreferredSize(new Dimension(50, 50));
add(setInv);
}
public static void main(String[] args) {
MyClass obj = new MyClass();
obj.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "set invisible") {
// I want an Accessor method for the parent JFrame and then I want to
// set it invisible here!
}
}
}
A person suggested getParent() method, but it is not working as I want!
getParent() returns some container in this case it is JFrame I think..
I have tried getParent().setInvisible(false);
but nothing happens..
I know it is error in my logic or something but what should I do?
Java is flexible but full of exceptions at many points!
there is one thing that if I dont extend MyClass from JFrame and create a public instance of JFrame and then setVisible(false); can be called by its reference!
but i do not want to do so...because i have made a project with a lot of classes and i do not want to change my code like this...
any help guys!