Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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.
------------------
 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic