• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make "doEvents" in JApplet?

 
Jorma Ikonen
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have an JApplet what loads quite much data from a servlet. The loading of data might take a lot of time and I would like to inform user about proceeding. So, I added an JEditorPane where the status of loading should be seen, but the text can't be read until everything is loaded (function have been performed) - See examaple below:
void getServersButton_actionPerformed(ActionEvent ae)
{
statusPane.setText("Now loadind data from...");
//any of those two lines below
//do not refresh the pane
//until the function have been totally performed.
this.repaint();
statusPane.repaint();
...
try
{
readData = dataTransfer(sendData);
}
catch (Exception ex)
{
statusPane.setText(ex.getMessage());
error = 1;
}
...
I also tried to use JApplet's run()-method to refresh te display by implementing Runnable-interface, but the result was same: First the data was loaded and then display updated.
What I should do? Do I have to create a new class from the JEditorPane what implements Runable-interface and call repaint()-method there?
br,
Jorma Ikonen
 
Tim Holloway
Saloon Keeper
Posts: 18359
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your biggest problem may be in trying to upload the data in a single request. That has less overhead, but it's an atomic operation.
If you prefer, you might break the data up into chunks and load it that way:
 
Jorma Ikonen
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have tried quite similar ways as your example, but no success. Are your sure that this a bit modificated example should work also?
void getServersButton_actionPerformed(ActionEvent ae)
{
JTextArea statusPane = new JTextArea();
while ( haveMoreChunks() )
{
statusPane.setText("Loading chunk...");
statusPane.repaint();
repaint();
downloadNextChunk();
}
}
I'm sure that the textarea is empty until getServersButton_actionPerformed()-function is prosessed totally. (It seems that the repaint()-function is ignored until the end of getServersButton_actionPerformed()-function.)
br,
Jorma
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jorma,
Go back to your original code and add a System.out.println call immediately before the call to repaint. If it gets executed then you might want to try this weird idea. It might or might not work but it is worth a try:
replace
this.repaint();
with
this.update( this.getGraphics() );
seems similar but it should immediately call the paint method instead of placing an event inside the event queue for later execution.
Regards,
Manfred.
 
Jorma Ikonen
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
It really works - thank you very much!
//this updates only the statusPane
statusPane.update(statusPane.getGraphics);
//this updates all (buttons, textfields, etc.)
this.update(this.getGraphics);
The note of the latest one is that it "raises" pushed button up even the process is still going on. It's not a problem, but (at least it) requires of using button.enable()-function (+ HourGlass) to prevent of giving wrong signal of non-finished process.
I happy that now I have an applet what can inform user where it's going on that the legend of jamed java-applet is reduced a bit.
Regards,
Jorma
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic