Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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
  • 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

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.
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. 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