Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8984839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:12:14+00:00 2026-06-15T21:12:14+00:00

I am developing a program by using JFrame and i want to realize that

  • 0

I am developing a program by using JFrame and i want to realize that when you click on a button, a loop in a other class has to work. It is working but so slowly. In one second you can see just one iteration of the loop. I dont understand why. There are pieces of codes you need to know.
Calling listener:

playWithComputerButton.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            startLoop(1);
        }
    });

called piece:

if(gameMode == 2){
        int i = 0;
        while(i < 500){
            int pos = ((Computer) playerA).thinkIt(board.getBoard());
            display("bu pas : " + pos);
            i++;
        }

There is no problem with iteration and calling listener. (i have tried it also with other iterations and ‘ActionListener’ but the result is same.

What can be the solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:12:15+00:00Added an answer on June 15, 2026 at 9:12 pm

    To perform long operations not related to GUI, we can simply make use of javax.swing.SwingWorker, as Nikolay Kuznetsov and MadProgrammer explained above.

    Here is a example of how to use it: example and here is the javadoc of SwingWorker: javadoc

    in case of my program, the solution is:

    Firstly create a new SwingWorker extending class in your JFrame class

    class LoopWorker extends SwingWorker<Integer, Integer>
    {
        protected Integer doInBackground() throws Exception
        {
            // perform your loop
        }
    
        protected void done()
        {
            // what has to be done after performing
        }
    }
    

    Then, the button should call its execute method as follow:

    learnButton.addActionListener(new ActionListener() {
    
            public void actionPerformed(ActionEvent evt) {
                new LoopWorker().execute();
            }
         });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a program using Windows 7. There are WCF services (soap, rest) that
I am developing program on window's using msys and mingw. I want to have
I'm developing a program that I'm using a string( generatedCode ) that contains some
I am developing a program that I want to share with certain people, however
I am developing a Java program using Eclipse that should exit with different codes
I'm developing a program that load webpages using WebBrowser control in VB6. How do
I'm developing a program using App Inventor that will tweet stuff. I've assigned a
I'm developing a program using PyQt4 and sqlite, I want to include a small
I'm developing a program using GOogle Places API and it has two functions: searchPlaces
I'm developing a program that displays graphical windows using the windows API. Below is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.