• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Updating Components

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am making my first "Top to Bottom" application, (an applet) which computes all of the prime numbers between two starting values. I am displaying the results in a JTextArea. I am also attempting to provide error messages and updates in the same area. I do a:
theText.setText("Computing the primes ...");
just before I do the computations and the messate does not show up. I have tried adding:
repaint();
after it but this message is skipped. I did an:
Graphics screen
...
theText.update(screen)
and while this got the message to display it also generated a NullEventException.
While I could trap the exception, that is not very clean. I am NOT currently using threads. Is this my problem?? Does Java not have enough time to update the display before my other computations have completed and they get displayed?
 
Trailboss
Posts: 23773
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, you say something about how this is an applet and an application. Usually these are two different animals. I suggest that you stick to application and introduce the applet factor later.
I think to see the message you will have to implement a thread. Java will do the actual painting while waiting for events - but you aren't waiting for events yet, you are working on the computations.

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My apologies, I am still getting familiar with Java terminology. My old school education terms everything an application.
This is an applet. It works great, except this one text message does not display. I have considered introducing threads by since what I am doing is very linear, I didn't see the need.
 
paul wheaton
Trailboss
Posts: 23773
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's been a while since I had to do this - before Swing, I made a progress bar. In order for the progress bar to show anything, I remember I had to put it in its own thread. I wish I could remember more details for you.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try paintImmeditly() on the component after
setting the component.
reply
    Bookmark Topic Watch Topic
  • New Topic