• Post Reply Bookmark Topic Watch Topic
  • New Topic

Closing a frame

 
Mark Lockery
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to have the program close the first frame when i open the second one, what i have tried does not work.



Also if anyone knows why my key presses don't work that would be useful too.

Thanks in advance.

by the way i have checked the rest of the forum and whenever somebody had a question on this type of thing either they stopped trying to do it this way, or nobody gave them a solution.

I'm assuming there's something special i have to do with the dispose method....
[ August 01, 2004: Message edited by: Mark Lockery ]
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.exit is lights–out, all done. You can call dispose on your first frame to remove its peer and make it go away.

You only need to load an image once. Do this in or via (a method call in) your class constructor. The paint method is not the place. To get an idea of how often java calls a Container or Canvas paint method try putting in a System.out.println("paint") statement and see what shows up in the console as you play your game.

Although the Frame (GameScreen1 is a Frame by extension) will accept a KeyListener it won't be listening if the focus is on GameCanvas1 (I altered the class names so you could run this without name collision problems). Your key code works okay now.

The boundry–checking code in the GameCanvas1 paint method rightly belongs in your (key) event code.
 
Mark Lockery
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't thank you enough Craig

I'm obviously new to java and this stuff is for an assignment for school. I've had these problems since just about day one and you solved them both. I'm so happy

Thanks again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!