• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Frame Trouble

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
------------------
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
------------------
 
The moustache of a titan! The ad of a flea:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic