Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (756)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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 2504 times)
0 Members and 1 Guest are viewing this topic.
Offline yossis

Junior Newbie

Java games rock!

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

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?

Offline Herkules

Senior Devvie

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 Devvie

« 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 .
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):


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 Devvie

« 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 .
Pages: [1]
  ignore  |  Print  

DesertCoockie (54 views)
2018-05-13 18:23:11

nelsongames (86 views)
2018-04-24 18:15:36

nelsongames (76 views)
2018-04-24 18:14:32

ivj94 (761 views)
2018-03-24 14:47:39

ivj94 (93 views)
2018-03-24 14:46:31

ivj94 (645 views)
2018-03-24 14:43:53

Solater (106 views)
2018-03-17 05:04:08

nelsongames (187 views)
2018-03-05 17:56:34

Gornova (428 views)
2018-03-02 22:15:33

buddyBro (1088 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!