Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Frame Trouble

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
------------------
 
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic