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 ???
IkelcaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
Swing is single threaded so you need to do long tasks in a background thread

SwingWorker is great for this sort of thing
Gurvinder Pal SinghCommented:
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/
colr__Commented:
public void actionPerformed(ActionEvent ev){
     new Thread(){

     }
}
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

colr__Commented:
Something went a bit whacky there, Iw asnt finished posting!

public void actionPerformed(ActionEvent ev){
     new Thread(){
          doYourSevenMinuteTask();
     }.start();
}
IkelcaAuthor Commented:
hi colr

i got illegal start of type error on "this.loadFiles();" line, do u know what causes it??

public void actionPerformed(ActionEvent ev){
     new Thread(){
          this.loadFiles();
     }.start();
}
Mick BarryJava DeveloperCommented:
>           this.loadFiles();

try:


          loadFiles();
colr__Commented:
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.
IkelcaAuthor Commented:
That means I have to create a new main instance and refer loadfiles() method thru new instanc?
colr__Commented:
What about this?

public void actionPerformed(ActionEvent ev){
     new MyThread().start();
}

public class MyThread extends Thread{
    private void loadFiles(){
     .....
    }

    public void run(){
        loadFiles();
    }
}
colr__Commented:
You dont have to create a new public class though, you could do it the way my original suggetion works and use an anonymous class. My declaration was a bit wrong though in my original, it should have been this:

public void actionPerformed(ActionEvent ev){
     new Thread(){
        public void run(){  
            loadFiles();
        }
     }.start();
}

private void loadFiles(){

}

This will work - your inner anonymous class has access to the private methods of the outer class.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IkelcaAuthor Commented:
I will try again and come back
Thanks
IkelcaAuthor Commented:
ok i tested, it worked partially, my main GUI still getting frozen a little bit
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.