File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem clearing and resetting a JPanel

 
Michael J Horn
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone,

Trying to put the finishing touches on my program for my programming class. Still just trying to wrap my brain on GUI. I believe I have everything working right more or less, but I can't get the new menu item to reset the game board with a new set of cards.

I have attached my code as a .zip file that can be imported into eclipse right away if anyone has a couple minutes to give a college student a couple pointers. I wasn't sure how to embed it below. Its javadoc'd and with comments so it should be pretty easy to read. I've been debugging all day and just can't figure it out.

The program compiles and you can run it as is a see for yourself. Thanks for any suggestions and help. I've tried recalling main which of course just creates another window, and assigning mainPanel to a new call of createGamePanel(). I just can't figure it out.

Thanks


 
Michael J Horn
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just realized i couldn't attach the .zip so I attached the java files instead real quick.
 
Michael J Horn
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haha wow can't catch a brake. I've just copied and pasted below.



 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, Mike. Welcome to JavaRanch, champ!

Well, what you can do is, you can create an ActionListener that listens to the menu item that resets the game and set it in the menu item that resets the game. This ActionListener will have access to the window, and there, you can create a public method that resets the game. This method can instantiate a class that extends Container (and represents the game board) and set it as content. Something like this:



This is just a suggestion of how you can organize your code. Please take a look at that and let us know how it goes!
 
Michael J Horn
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, that really helped! I just adapted that layout to my own and it worked well. I appreciate it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic