wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Swing Jpanel not updating on a certain call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing Jpanel not updating on a certain call" Watch "Swing Jpanel not updating on a certain call" New topic
Author

Swing Jpanel not updating on a certain call

Matthew Lannom
Greenhorn

Joined: Dec 30, 2013
Posts: 2

Hello This will be my first post and my name is Matthew. I've read though head first java(and am doing it again also design by the same people)
I've been working on this game for some time and it worked in the command line, but I've run into problem after problem once
I've moved to Swing.

Main class(gutted to show where things are happening)


Gui class



When the new room is called to create buttons for movement there is no problem but when
this bit of code(below) is called below it freezes up on updates to the gui. However the system.out.println still work.
So the methods are run though but the updates can't be seen. If this is obvious I greatly apperciate being pointed in the right direction.
Thank-you for your help.


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38005
    
  22
Welcome to the Ranch
I had to break some of your lines because they were too long.

Your code looks confused. I think what has happened is that you do not have an interface for your game. You should have a load of public methods which instruct the game to take the next move, retrieve details of the room baddie count, etc etc. Then you call those methods from the GUI.
Why are you removing buttons from the display? That will make it look very strange. You know you can enable or disable buttons?
You haven't shown us the code which causes changes to the GUI. Only the add buttons and remove buttons methods. How are you calling them? I don't think we can help until we see that.
Which thread are you running that code in? System.out.println(Thread.currentThread().getName());
Why are you using Flow Layout? I think flow is a particularly useless layout.
Never write == true or == false, which are both poor style and error‑prone if you write = instead of ==. Not if (b == true)... or if (b == false)... but if (b)... and if (!b)...
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2153
    
    7
The basic code when you remove/add components to a panel is to use:

Matthew Lannom
Greenhorn

Joined: Dec 30, 2013
Posts: 2

Campbell Ritchie wrote:Welcome to the Ranch
I had to break some of your lines because they were too long.

Your code looks confused. I think what has happened is that you do not have an interface for your game. You should have a load of public methods which instruct the game to take the next move, retrieve details of the room baddie count, etc etc. Then you call those methods from the GUI.
Why are you removing buttons from the display? That will make it look very strange. You know you can enable or disable buttons?
You haven't shown us the code which causes changes to the GUI. Only the add buttons and remove buttons methods. How are you calling them? I don't think we can help until we see that.
Which thread are you running that code in? System.out.println(Thread.currentThread().getName());
Why are you using Flow Layout? I think flow is a particularly useless layout.
Never write == true or == false, which are both poor style and error‑prone if you write = instead of ==. Not if (b == true)... or if (b == false)... but if (b)... and if (!b)...



Sorry I gutted those because I thought they would just add more lines that people would not want to see.

here is the complete main class code




Thank-you for that input I'm sorry things are confusing. I did not know I could enable and disable buttons
I'll look into making your suggested changes thank-you
EDIT: Running the suggest println segment only gives
AWT-EventQueue-0


EDIT2: if it helps I'll explain the basic idea of the game. The player is presented with text explaining what is
happening in a textArea below the text area is a panel that will fill with button that the player can then
choose from. In this case the buttons are move, search, and inventory. When move is pressed it then removes
those button and then adds the new set of options. On testing where the exits are in the room it will then display
buttons saying north, south, etc. The movement and those buttons work just fine and add/remove just fine. However
once we get to the area where it goes to call the battle it stops working. The updates to the gui stop however the methods all
get called and ran just fine.

Again I thank everyone and anyone for help given and offered.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Swing Jpanel not updating on a certain call
 
Similar Threads
Null Pointer Exception
trying to center buttons with fixed sizes
Problem with a method in my EJB
Scrollbar not working
about threads.. there's something wrong though i can't seem to find it