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 6923187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:30:12+00:00 2026-05-27T10:30:12+00:00

I am trying to make this button disable the two other buttons and execute

  • 0

I am trying to make this button disable the two other buttons and execute something graphical at the same time. This is the first thing I tried:

public void actionPerformed(ActionEvent arg0) {
    reset.setEnabled(false);
    switcher.setEnabled(false);
    for (int i = 0; i < 10; i++){
            a.change();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
            return;
        }
    }
}

So this is the actionperformed method on the button I’m trying to code and switcher and reset are the buttons I’m disabling, and a.change() is supposed to cause a visual effect. When I tried this, the whole program stopped for ten seconds, and then the buttons disabled, with no visual effect during those ten seconds. Then I tried:

public void actionPerformed(ActionEvent arg0) {
    reset.setEnabled(false);
    switcher.setEnabled(false);

    if (!s.isAlive()){
        s = new Thread(new Changer());
        s.start();
    }
    else{
        s.interrupt();
    }
}

Where Changer is:

private static class Changer implements Runnable {
    public void run() {
        for (int i = 0; i < 10; i++){
            a.change();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
                return;
            }
        }
    }
}

This worked exactly how I wanted, with the buttons immediately being disabled, followed by the visual effect. Is the reason for this that all of the effects of actionperformed activate upon exiting the function, so the first way, it would ten seconds for actionperformed to end, and the it would do both disables and ten a.change()s at the end? And the second way it resolves after starting s, so the buttons disable, and then s continues and does its effect after actionperformed has ended?

  • 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-05-27T10:30:12+00:00Added an answer on May 27, 2026 at 10:30 am

    Yes.

    There’s a single UI thread managing events and repainting (updating the screen). In your first attempt you put it to sleep. Doing so meant that nothing else was going to happen (in regard to the UI) until it woke up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$('#div1').focus(function () { callAnotherFunction(); $(this).animate({}); } I'm trying to make $(this).animate({}); execute after callAnotherFunction();
I am trying to make two ajax requests in parallel using jQuery like this:
I'm trying to make this button change background when you click it and this
I am trying to make a stop button for this loop but it runs
I'm trying to make a rounded button using -webkit-border-radius This gives me this button
I am trying to make this landscape only iphone app. I only use this
I'm trying to make this fragment work: Version History --------------- These are the versions
I have been trying to make this to be a little jQuery plugin that
I'm trying to make this code generic: public final Object unwrap(Class arg0) { throw
I'm trying to make this command: sed bla bla filename | awk '{printf %s

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.