Meaningless Drivel is fun!*
The moose likes Threads and Synchronization and the fly likes Problem with swing GUI due to lengthy code running in background. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Problem with swing GUI due to lengthy code running in background." Watch "Problem with swing GUI due to lengthy code running in background." New topic
Author

Problem with swing GUI due to lengthy code running in background.

krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Hi all, I have been studying about threads, I am unable to implement event dispatching. I have read a lot in the web, but there are no bold examples available. I only understood the concept. But unable to implement it. Moreover I am unable to understand invokeLater() usage.

Lengthy programs are placed, I am unable to understand them. Please can anyone tell me how to implement this one with an example program.

I am working on an application, where I will be sending messages to mobiles from a system using a GSM modem. I want to implement this one in my application.

I have coded the entire thing, but the problem is once I hit the send message button the GUI is becoming inactive, after sending all messages it is becoming active.

Then I understood that I have to use Event Dispatching concept. Can anyone help me with small examples?

Thank you all in advance, have a great day.


There is no rule that we all should know everything. Lets learn few things of everything here.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

SwingUtilities.invokeLater is used to make a task run in the Event Dispatching Thread. Which means that it won't block the running process. There's a simple example in the API. If you are using Java 1.6, you can also make use of the SwingWorker class to interact with your UI, without blocking the running thread. If you're not, then you can get the SwingWorker here.


[My Blog]
All roads lead to JavaRanch
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Hi Christophe, I searched the internet, I am unable to understand those examples really, and I am using java 1.6. I have seen SwingWorker class also, but before understanding the basic programs how can I understand that. Please can you give me a sample program. I know that we cannot expect code here, but I want a sample program, I will see it and learn.

Thank you in advance, have a nice day.
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Is there anyone who can help me?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

DId you check out the SwingWorker link Christophe provided? It contains sample code with explanations.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
No Maneesh, I did not understand that. Thats what I am saying from beginning.
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Hi all, after studying a lot about the stringworker class, I wrote this program seeing an example. This one.


My aim is to verify the entered password. The password is in a text file in an encrypted format(MD5). I am using a class called "Verify". There is a function in it which will take the entered password and check whether it is right or wrong. Since this may take some time, opening a file, decrypting the password and comparing it, so I decided to go with StringWorker class. I have done up to here. Now I dont know what to do.

Can anybody help me please. Thank you all in advance. Have a nice day.
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Anybody there!!!
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42277
    
  64
Well, more than two days have passed since you were pointed to SwingWorker page, so you must have read the page by now, and also the javadocs of that class. Have you run the example codes shown there? Did you understand what it's all about? If not, what -exactly- is still unclear about it?

(And no, the solution does not involve extending the SwingWorker class.)

I'd also advise not to post anything that ends in multiple exclamation marks - that's very unlikely to make people here want to help you.


Ping & DNS - my free Android networking tools app
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Hi Dittmer, sorry for the exclamation marks, I was really tired waiting for it.

Somehow I have done this one, I don't know whether this way is correct or not, but I got the expected output. I have understood the concept, just for simulation I am doing this program.

I did not understand this one.
(And no, the solution does not involve extending the SwingWorker class.)

The new code is this


Please tell me if I have done anything wrong. Once again I am sorry. Thank you in advance.
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Hi all, now I am understanding the concept, I am leaning it and able to feel it, if i get any doubts I ll return.

Thanks for the help and sorry for being rude. Have a nice day.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42277
    
  64
I was really tired waiting for it.

That was obvious, but posts here are at the discretion of our visitors - so any given question may never be answered. Becoming impatient over that really doesn't accomplish anything (besides possibly turning off people from answering). But all is good now :-)

I did not understand this one.
(And no, the solution does not involve extending the SwingWorker class.)

I see what you're doing now; in light of that, i retract that statement.
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Hi Dittmer you are right, thanks for correcting me, I wont repeat this again.
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Hi everybody, I have a doubt, can I have to inner classes which extend SwingWorker class?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

krishna Karthikk wrote:Hi everybody, I have a doubt, can I have to inner classes which extend SwingWorker class?


It may be a good idea to start a new topic for a new question -- as this topic has been resolved.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with swing GUI due to lengthy code running in background.