Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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  
  Swing Components Blocking  (Read 1130 times)
0 Members and 1 Guest are viewing this topic.
Offline dudley442

Senior Newbie




Java games rock!


« Posted 2004-08-26 19:24:00 »

Hey everyone,

Now I've been programming for nearly two years in Java, but this one little tidbit has got me stumped.

I've got two separate threads running.  One doing painting in a JFrame, and the other performing I/O work.

For some odd reason, when the I/O thread is doing its thing, the components refuse to paint in the JFrame.  Even if I try calling repaint(), it will ignore the call until the I/O has finished.

Any ideas?
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #1 - Posted 2004-08-26 20:45:34 »

Need more info.  What is the I/O thread doing exactly?  Is it interacting with any of the UI stuff at all?

Offline trembovetski

Senior Duke




If only I knew what I'm talking about!


« Reply #2 - Posted 2004-08-27 01:03:29 »

It'd help if you can post a stack trace when the IO/not painting happens (Ctrl+Break on win, Ctrl+\ on unix).
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dudley442

Senior Newbie




Java games rock!


« Reply #3 - Posted 2004-08-27 15:36:11 »

There is no interaction with the UI whatsoever.  What the I/O is doing is reading in a list of files and writing their absolute pathnames to a text file.  It is on a completely separate thread from the GUI.

The thread that is running responsible for painting in the JFrame may make a call during the I/O operation like:

System.out.println(System.currentTimeMillis());

And that will work; but, for some reason, the painting functions will not.  The JFrame stays blank until the I/O operation ceases.
Offline kevglass

JGO Kernel


Medals: 188
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #4 - Posted 2004-08-27 15:40:23 »

Are you calling repaint() with no arguments? If so, that actually just indicates to the AWT thread (running in the background) that the window should be repainted as soon as possible.

If you call repaint(long ms) where ms is the number of milliseconds that are "allowed" to pass before the repaint of the window occurs. Calling repaint(0) should force instant repaint.

However, if your I/O thread is running at full speed (i.e. no sleep() or yield()) then on some system it'll block other threads altogether.

Kev

Offline dudley442

Senior Newbie




Java games rock!


« Reply #5 - Posted 2004-08-27 15:52:14 »

Whoops!  Grin

As sure as I was yesterday that the I/O operation was being done on a totally separate thread, it turns out that I was wrong about that.

Thanks for the help, though.  That repaint(0) call will definitely come in handy.

Anyway, I was making a program which writes the absolute pathname of each and every single file and folder inside a given directory to a specified text file.  Works now.
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.

theagentd (5 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (45 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (38 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!