• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

How to make GUI wait for user input? [duplicate]

August 23, 2017 by

Questions › How to make GUI wait for user input? [duplicate]
0
Vote Up
Vote Down
Garmaine asked 6 years ago
This question already has an answer here:
http://stackoverflow.com//questions/7778441/how-to-stop-java-from-running-the-entire-code-with-out-waiting-for-gui-input-fro”>How to stop Java from running the entire code with out waiting for Gui input from The user (1 answer)
Closed 2 years ago.

I'm a rather basic programmer who has been assigned to make a GUI program without any prior experience with creating a GUI. Using NetBeans, I managed to design what I feel the GUI should look like, and what some of the buttons should do when pressed, but the main program doesn't wait for the user's input before continuing. My question is, how do I make this program wait for input?

    public class UnoMain {

    public static void main(String args[]) {
        UnoGUI form = new UnoGUI(); // GUI class instance
        // NetBeans allowed me to design some dialog boxes alongside the main JFrame, so
        form.gameSetupDialog.setVisible(true); // This is how I'm trying to use a dialog box

        /* Right around here is the first part of the problem.
         * I don't know how to make the program wait for the dialog to complete.
         * It should wait for a submission by a button named playerCountButton.
         * After the dialog is complete it's supposed to hide too but it doesn't do that either. */

        Uno Game = new Uno(form.Players); // Game instance is started
        form.setVisible(true); // Main GUI made visible
        boolean beingPlayed = true; // Variable dictating if player still wishes to play.
        form.playerCountLabel.setText("Players: " + Game.Players.size()); // A GUI label reflects the number of players input by the user in the dialog box.

        while (beingPlayed) {
            if (!Game.getCompleted()) // While the game runs, two general functions are repeatedly called.
            {

                Player activePlayer = Game.Players.get(Game.getWhoseTurn());
                // There are CPU players, which do their thing automatically...
                Game.Turn(activePlayer);
                // And human players which require input before continuing.

                /* Second part of the problem:
                 * if activePlayer's strategy == manual/human
                 *   wait for GUI input from either a button named 
                 *   playButton or a button named passButton */

                Game.advanceTurn();
                // GUI updating code //

            }
        }
    }
}

I've spent about three days trying to figure out how to integrate my code and GUI, so I would be grateful if someone could show me how to make this one thing work. If you need any other information to help me, please ask.

EDIT: Basically, the professor assigned us to make a game of Uno with a GUI. There can be computer and human players, the numbers of which are determined by the user at the beginning of the game. I coded the entire thing console-based at first to get the core of the game to work, and have since tried to design a GUI; currently this GUI only displays information about the game while it's running, but I'm not sure how to allow the code to wait for and receive input from the GUI without the program charging on ahead. I've investigated other StackOverflow questions like this, this, this, or this, but I cannot comprehend how to apply the answers to my own code. If possible, I'd like an answer similar to the answers in the links (an answer with code I can examine and/or use). I apologize if I sound demanding or uneducated and confusing; I've been working diligently on this project for a couple weeks and it's now due tomorrow, and I've been stressing because I can't advance until I figure this out.

TL;DR – How do I get my main program to wait and listen for a button click event? Should I use modal dialog boxes, or is there some other way to do it? In either case, what code needs to be changed to do it?

Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: java, user-input, user-interface

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Copyright © 2023