Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

The background is not displayed  RSS feed

 
Peter Sorotokin
Ranch Hand
Posts: 36
1
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have writen an application that consists of three java files .
1 - Ping.java
2 - ImagePanel.java
3 - ShowColors.java

This app works correctly and very good . This app display the map of an office as background and determine an spot on it ( a network switch ) . If that switch is connected to main server ( is pinged ) , the spot becomes green and if not becomes red . It work correctly until i wanted to test this condition endless and added this line to ImagePanel.java : while ( true ){ .... } ( line 32 )
After that the background is not displayed and the app hanged . I know that maybe to be better way to do ping check endlessly . But why the background is not dispalyed ? What is the better way to check the ping command endlessly ?



 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The background won't be displayed until control returns from the paintComponent method. But your paintComponent method has an infinite loop in it.

So don't do that. Just have the paintComponent method display the image and be done with it. If you want to do something repeatedly in a Swing application then a Swing timer is the tool you should be using.
 
Maxim Karvonen
Ranch Hand
Posts: 121
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pinging itself may be a long-lasting operation (4 sec timeout in code). If this code is executed in EDT then all UI will freeze during that operation. I expect SwingWorker will be much better than Swing timers for this task.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a good point, Maxim.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!