Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 979
  • Last Modified:

how to kill jframe

hi can i ask how to kill all the visible jframe from java applet  thanks
0
emeraldpiggy
Asked:
emeraldpiggy
  • 8
  • 5
  • 4
  • +1
2 Solutions
 
Kamaraj SubramanianApplication Support AnalystCommented:
have you tried dispose method ?
0
 
emeraldpiggyAuthor Commented:
hi itkamaraj
how do u dispose all the existing jframe?
0
 
arevuriCommented:
frame.dispose()
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
emeraldpiggyAuthor Commented:
? i assume frame is the instance name of the jframe that i created?
so i ll have to do a loop to get all the frame names then dispose them one by one?
0
 
emeraldpiggyAuthor Commented:
what i am trying to achieve is reset all the jframe to its original state.
dispose the old one then immediately open a new one
0
 
arevuriCommented:
you are right frame is object just like your jframe.
 
public void dispose()  --- description from Java doc
Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.
The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show. The states of the recreated Window and its subcomponents will be identical to the states of these objects at the point where the Window was disposed (not accounting for additional modifications between those actions).
Note: When the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for more information.

See Also: Component.isDisplayable(), pack(), show()
0
 
emeraldpiggyAuthor Commented:
So mind me asking how do I use dispose in this situation ?
For example when I click create button it will dispose old jframe then create a new one
thanks
0
 
CEHJCommented:
You might be better off keeping your frames in an array
0
 
emeraldpiggyAuthor Commented:
Hi may I ask are there  Any sample code that demostrate it? Thanks
0
 
CEHJCommented:
e.g.
	final JFrame[] frames = new JFrame[6];
	for(int i = 0;i < frames.length;i++) {
	    frames[i] = new JFrame();
	    ...
	    frames[i].setVisible(true);
	}
	...
	// Close them
	for(int i = 0;i < frames.length;i++) {
	    if(frames[i].getVisible() {
		frames[i].dispose();
	    }
	}

Open in new window

0
 
emeraldpiggyAuthor Commented:
thanks cehj
my problem is i couldnt close the open with one button
I couldnt identify the frame before i close them
thanks
button = new JButton("Go");
button.addActionListener(new ButtonListener());

class ButtonListener implements ActionListener {
	  ButtonListener() {}
	  public void actionPerformed(ActionEvent e) {
		    if (e.getActionCommand().equals("GO")) {
		    	JFrame jf = new JavaChess1();
		    	jf.setVisible(true);
		    }
		  }
}

Open in new window

0
 
CEHJCommented:
You would need to add the new frame to an array or List as i showed
0
 
emeraldpiggyAuthor Commented:
hi cehj
i can add the new frame into an array
but what code i should use to close it and when?
thanks
0
 
CEHJCommented:
If you need to identify the frame, set the name property. See setName. Then you can iterate the array looking for something of that name
0
 
arevuriCommented:
or try setting null value to your frame
0
 
arevuriCommented:
sorry by mistake I fired enter key
try setting null value to your frame after invoking dispose method and create new one when ever you require
0
 
emeraldpiggyAuthor Commented:
thanks
its not working exactly as i wanted
0
 
CEHJCommented:
>>its not working exactly as i wanted

Is there still a problem?
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 8
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now