• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Problem clearing and resetting a JPanel

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Haha wow can't catch a brake. I've just copied and pasted below.



 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic