This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Problem clearing and resetting a JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem clearing and resetting a JPanel" Watch "Problem clearing and resetting a JPanel" New topic
Author

Problem clearing and resetting a JPanel

Michael J Horn
Greenhorn

Joined: Oct 13, 2011
Posts: 4
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

Joined: Oct 13, 2011
Posts: 4
Just realized i couldn't attach the .zip so I attached the java files instead real quick.
Michael J Horn
Greenhorn

Joined: Oct 13, 2011
Posts: 4
Haha wow can't catch a brake. I've just copied and pasted below.



Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

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!


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Michael J Horn
Greenhorn

Joined: Oct 13, 2011
Posts: 4
Thanks a lot, that really helped! I just adapted that layout to my own and it worked well. I appreciate it.
 
wood burning stoves
 
subject: Problem clearing and resetting a JPanel
 
Similar Threads
Character shuffle
Figuring out when a JTextComponent is full
working with book, code compiiles but won't run
Tricky NullPointerException Problem
FTP Client