How to use the same instance of an object in two methods
My issue is that in my code, I create a new JFrame object called frame. In another method I want to close that frame. Any suggestions?
Code :
// Non-relevant code
private static class oddbutton implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
//More Non-relevant code
public void run(){
NewGame.setoddnumber();
NewGame.setevennumber();
NewGame.separate();
JFrame frame = new JFrame("Button Game!");
addComponentsToPane(frame.getContentPane());
Insets insets = frame.getInsets();
frame.setSize(200, 300);
frame.setVisible(true);
}
As of now, I have nothing in my oddbutton class. I don't know how to close the frame.
Re: How to use the same instance of an object in two methods
Never mind. I solved my issue. All I had to do was make frame a static public object.
Re: How to use the same instance of an object in two methods
Making something static to get around accessibility issues is a bad solution.
Re: How to use the same instance of an object in two methods
Quote:
Originally Posted by
Junky
Making something static to get around accessibility issues is a bad solution.
So, what else can be the solution to OP's specified problem?