Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (552)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Locking when using JTextField  (Read 1712 times)
0 Members and 1 Guest are viewing this topic.
Offline yossis

Junior Newbie




Java games rock!


« Posted 2005-04-01 11:18:17 »

Hi,
I'm using JTextField in my game to receive user input.
Problem is the game get stuck when i use the text field.
I tried to override the setText method and lock the text field  before setting its text but it didn't work.

Due to time constraints i don't want to create my own customized text field.
Any ideas on how can i prevent the locking?

Thanks,
Jo
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #1 - Posted 2005-04-01 12:20:49 »

I feel you will need to elaborate on what 'locking' means in your case and about the environment the JTextField gets to live in.

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline yossis

Junior Newbie




Java games rock!


« Reply #2 - Posted 2005-04-01 13:08:47 »

By locking i mean that the game simply get stuck...
It seems that there is some sync isues with the event dispatcher thread.
I'm using active rendering in my game and the game hangs when the text field has the focus and i call the layered pane's paintComponent method (not always but after few calls to the method).
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline digitprop

Junior Member





« Reply #3 - Posted 2005-04-01 15:47:36 »

Hard to tell what the problem might be, with so little information given.

Here are a few thoughts:

- Check whether you manipulate any Swing components outside of the AWT thread. The spec does explicitly not allow this, and it can actually lead to severe and rather unpredictable problems.

- Have you customized the JTextField (i.e. subclassed it, changed the look and feel)?

- Do you have any listeners registered which may get stuck?

- If possible, try to dig as deep as possible into the stack trace to see where the AWT thread hangs. Debugging into the Swing/ AWT classes works quite well with Eclipse, and usually gives you at least an indication what the problem may be (e.g. a lock on the component tree).

M. Fischer . www.digitprop.com
Offline yossis

Junior Newbie




Java games rock!


« Reply #4 - Posted 2005-04-01 16:57:03 »

Let me clear some things:
I'm using JFrame to render all game objects (bg image, game objects, huds etc.). For that i'm not using any swing components (except the JFrame itself).
At the end of the game i'm using JPanel as high scores menu. The panel uses text field for the name and two buttons.
When i try to enter text in the text field the game hangs after few seconds (with no exception but i can point the line it happens in the code).

The rendering is quite simple and looks something like this (gameFrame is the JFrame):

gameObjects.render(g);
gameFrame.getLayeredPane().paintComponents(g);

When the game hangs it always happens in the second line above.

I'm using some other menus with buttons only and they never cause any problems.

At first i used regular JTextField and when i realized it causes problems i subclassed it and synchronized the setText method (...synchronized (getTreeLock()) but it didn't work either.

I managed to prevent the locking by using EventQueue.invokeAndWait to call gameFrame.getLayeredPane().paintComponents(g) but i don't like this "solution" because it forces me to wait and use another thread.


Offline digitprop

Junior Member





« Reply #5 - Posted 2005-04-03 15:02:59 »

From where do you call the game rendering code? I assume that you call it from a game loop running in a separate thread.

If that is the case, the hanging is probably explainable. The paint() method of JComponent (which in turn calls the paintBorder(), paintComponent(), and paintChildren() methods) is not supposed to be called from any other but the AWT thread.

In general, Swing is not a multi-threaded framework, and many things can go wrong if you treat it as such.

If the above scenario applies, using invokeandWait() is valid and actually recommended. In that case, however, I would consider to simply use repaint() in your game loop, and implement the paint() method of the JFrame.

M. Fischer . www.digitprop.com
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (23 views)
2014-08-22 19:31:30

atombrot (34 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (28 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (41 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!