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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:19:27+00:00 2026-06-15T12:19:27+00:00

Possible Duplicate: How can I wait for a button press in a loop? I

  • 0

Possible Duplicate:
How can I wait for a button press in a loop?

I think this question has been asked before however I have not found a response that solves my situation.

I currently have a chess program (command line) that allows a user to input the coordinates of the square holding the piece that they would like to move. The beginning works like this.

boolean success;
do {
    success = true;

    // take in coordinates;

    // perform checks such as not empty square etc;

    if (/*problem found*/) {
        // print error message;
        success = false;
    }
}
while (!success);

This works great when running in a command line because each time the loop is run, the program pauses execution to wait for the user to input the coordinates. However, now I want to implement this with a GUI using buttons and action listeners. The most convenient solution would be not to change the code apart from the input coordinates section which would be replaced with something such as,

pause program;
user presses button which sets coordinates;
when button pressed program continues;
perform checks…;

How can this be done?
Is there a method in java that says wait for button press?
This method would have to insure that other parts of the program such as painting the GUI does not stop.

  • 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-15T12:19:29+00:00Added an answer on June 15, 2026 at 12:19 pm

    I guess you don’t need a “pause”. You need to call a function when a button is clicked. You can put the action to do into a function, then call this function from the Listener’s implementations. As your example says button, you can implement ActionListener to your Frame object, then actionPerformed() function calls your function.

    public class GUI extends JFrame implements ActionListener{
        //...
        Button b;
        public GUI(){
            //...
            b = new Button();
            this.getContentPane().add(b);
            this.addListener(b);
            //...
        }
        //...
        public void actionPerformed(ActionEvent e){
            if(e.getSource()==b){
                // your TODO list here
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can someone Explain this jQuery code? I have posted this before, but
Possible Duplicate: Wrap subprocess' stdout/stderr In this question , hanan-n asked whether it was
Possible Duplicate: Can jQuery provide the tag name? Hi! This question is so basic
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Can you animate a height change on a UITableViewCell when selected? This
Possible Duplicate: Can one do a for each loop in java in reverse order?
Possible Duplicate: Continue Execution Only After .each() Completes This question is actually a continuation
Possible Duplicate: How can I make the browser wait to display the page until
Possible Duplicate: How can I run a child process that requires elevation and wait?
Possible Duplicate: Can we post on Google plus from android application? According to this

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.