Ikelca
asked on
need help on java GUI application
my GUI part is really simply, just a text area and one start button, the text area is to display output
when button is clicked, it will run a method which runs for about 7 mins
now the problem is that after button is clicked, entire application is frozen and waiting for that method to finish....
how could i do to free GUI and button after button is clicked while method is running ???
when button is clicked, it will run a method which runs for about 7 mins
now the problem is that after button is clicked, entire application is frozen and waiting for that method to finish....
how could i do to free GUI and button after button is clicked while method is running ???
i think all you have to do is after the action listener has captured the button click event, you need to invoke the other methods inside asynchronously
http://cephas.net/blog/2004/02/02/asynchronous-method-invocation-in-java/
http://cephas.net/blog/2004/02/02/asynchronous-method-invocation-in-java/
public void actionPerformed(ActionEven t ev){
new Thread(){
}
}
new Thread(){
}
}
Something went a bit whacky there, Iw asnt finished posting!
public void actionPerformed(ActionEven t ev){
new Thread(){
doYourSevenMinuteTask();
}.start();
}
public void actionPerformed(ActionEven
new Thread(){
doYourSevenMinuteTask();
}.start();
}
ASKER
hi colr
i got illegal start of type error on "this.loadFiles();" line, do u know what causes it??
public void actionPerformed(ActionEven t ev){
new Thread(){
this.loadFiles();
}.start();
}
i got illegal start of type error on "this.loadFiles();" line, do u know what causes it??
public void actionPerformed(ActionEven
new Thread(){
this.loadFiles();
}.start();
}
> this.loadFiles();
try:
loadFiles();
try:
loadFiles();
Sorry, just back from lunch! As objects has said, using this won't work as it would refer to the Thread object rather than the object containging the loadFiles() method.
ASKER
That means I have to create a new main instance and refer loadfiles() method thru new instanc?
What about this?
public void actionPerformed(ActionEven t ev){
new MyThread().start();
}
public class MyThread extends Thread{
private void loadFiles(){
.....
}
public void run(){
loadFiles();
}
}
public void actionPerformed(ActionEven
new MyThread().start();
}
public class MyThread extends Thread{
private void loadFiles(){
.....
}
public void run(){
loadFiles();
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will try again and come back
Thanks
Thanks
ASKER
ok i tested, it worked partially, my main GUI still getting frozen a little bit
SwingWorker is great for this sort of thing