• Post Reply Bookmark Topic Watch Topic
  • New Topic

too long, waiting process..  RSS feed

 
erdem ozdemir
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

In my program, I want to show some pictures on the internet.

I am creating an URL object and making the adress of object to url of the picture then when I was using it to show pictures in my program I realized that, it takes too much time to obtain the picture and prevents my program responsing user's desires, clicks.

What I want is that, program should not be locked, and it should continue running properly simultaneously with downloading my picture, when it completes download of picture, it should show it..

Answers will be appreciated..
Thank you.
 
Felipe Walker
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create another class that extends Thread and let that class do the work of loading the picture. The new thread does the work of loading your picture while the rest of the application keeps working on it own thread.
 
erdem ozdemir
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hımmm, first I tried


This part creates an internal frame 'createInternalFrames' method includes part of obtaining the image, then I realized that I have to call sleep method of thread so it can give chance of processing to other tasks and I changed my code as below..





I thought that with the help of timer, it should stop some time the thread, but it does not help me too... Where did I do wrong, or could it be do in some other way ?
 
Felipe Walker
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what does the rest of the code look like?
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Felipe suggested, you should create ANOTHER thread. invokeLater simply places your task on the same GUI event thread as before. This problem comes up a lot and there's discussions here and a chapter in the The Java Tutorial which disucss the issues involved. Since this question is not about IO, I'm going to move it to the Swing forum.
 
erdem ozdemir
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Felipe, , the mistake is at me, I could not do what you said... And thank you, Joe for showing me the mistake at my code that I posted..
Now, the problem is solved...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!