Java Bluej

BigCoolJesus

Banned
Jun 22, 2005
1,687
0
0
Im making Battleship in Bluej just for the hell of it, and its almost done, but.......



Is there a command to use specific to a class to close just that class?

Like i know System.exit(0) closes everything, but i want it so that when a button is pushed, instead of closing the whole game, only one particular window (i have three different windows running during the game, each window has its own class) is closed?



Thanks.
 

Atheus

Diamond Member
Jun 7, 2005
7,313
2
0
Are you using swing or AWT? You should be able to call close() on the window...

 

BigCoolJesus

Banned
Jun 22, 2005
1,687
0
0
Originally posted by: Atheus
Are you using swing or AWT? You should be able to call close() on the window...

Apparently i have both AWT and Swing imported, so im not sure which one im using (im not that good at Java, average)

In the class i want to close, its just a Jframe with a container that has 2 buttons, and when one of the buttons is pressed i want my action method to close the window (container) that the buttons are in........


would i do the variable for my container.close()?
 

Atheus

Diamond Member
Jun 7, 2005
7,313
2
0
Sorry, it's not close(), it's dispose(), I haven't written a swing GUI in a while. All the methods are in the documentation for JFrame on java.sun.com if you want to check this sort of thing.

im not sure which one im using

Easily solved.

In the class i want to close, its just a Jframe

You are using Swing.

So, you want to add an ActionListener to the button with an ActionPerformed method containing frame.dispose();