aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Frame Trouble Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Frame Trouble" Watch "Frame Trouble" New topic
Author

Frame Trouble

Sam Battery
Greenhorn

Joined: Oct 05, 2000
Posts: 10
I've got a calculator type applet that pops up in a new Frame. It resizes, it deiconifies, it maximizes it minimizes, but it doesn't close when you click the close button in the upper right corner. I thought Frames had that built-in. Any help would be appreciated. BTW, this is not a JFrame. It's just an instance of AWT Frame.
------------------
Matthew Jones
Ranch Hand

Joined: Dec 21, 2000
Posts: 68
Unfortunatly, you have to write the code to close the window yourself(sort of). I believe that it generates an event when you click on the close button, but you then have to capture it and destroy the window. Not exactly sure how, but one way would be to setVisible(false) and then set the frame equal to null. There may be a better way or a method written already, but I don't know what it is.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi,
When working with Frames you need to add a window event handler to handle all the different stuff (7 different event types):
windowActivated (show)
windowClosed,
windowClosing,
windowDeactivated,
windowDeiconified,
windowIconified, and
windowOpened.
Lucky for us, AWT offers us a class that has stubs for all 7 types: WindowAdapter. To use it with your frame:

This will remove your window when the 'X' system button is hit on the window frame.
Enjoy,
Manfred.
Sam Battery
Greenhorn

Joined: Oct 05, 2000
Posts: 10
I've copied and pasted this and it still doesn't work. I get an "invalid method declaration error" on calculator.addWindowListener.
------------------
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Jeff,
I am not understanding your layout. According to what I read you are starting up a frame that has the calculator in it. If that is the case then you need to add the windowListener to the frame and not calculator...
Manfred.
Sam Battery
Greenhorn

Joined: Oct 05, 2000
Posts: 10
My Frame is called calculator
Frame calculator = new Frame("State Alcohol Tax Calculator");
calculator.addWindowListener(
new WindowAdapter()
{
public void windowClosing( WindowEvent we )
{
// Call Frame supplied method to close window!
dispose();
}
});
I can't figure it. I've got all the appropriate imports too.
------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Frame Trouble