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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:53:07+00:00 2026-05-19T16:53:07+00:00

i have a problem with the order of players. I need that the first

  • 0

i have a problem with the order of players. I need that the first player be the winer of round. So i have, four buttons, there is any possibility to block the move of incorrect player, something like “is not your turn, player two is the first because is the winer of previous round”

how i can control that? eventually a method to verify

i have four labels for cards, and five cards in hand for each player

for each button, set the correspondent card i do

//PLAYER1
    //card1 
    ActionListener one = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (gr.getCounter1() < 5) {
                gr.setCounter1(gr.getCounter1() + 1);
                test1.setIcon(play1a);
                pn1.setText(Integer.toString(play2a));
                pn5.setText(play3a);
                pn50.setText(play4a);
            } else {
                pn5.setText("No more cards");
            }
        }
    };

    arraybtn[1].addActionListener(one);
    arraybtn[1].setPreferredSize(new Dimension(120, 20));

    play1a = gr.GameRules1().getImage(); //image of card
    play2a = gr.GameRules2(); // value
    play3a = gr.GameRules3(); // king of hearts for exemple
    play4a = gr.GameRules4(); // hearts

    arraybtn[1].setText(gr.GameRules3()); // button name
  • 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-19T16:53:07+00:00Added an answer on May 19, 2026 at 4:53 pm

    How many classes does your program have? Hopefully it has a non-GUI model that drives the GUI, and it should be this very same model that dictates the control of game play. Rather than throw an error as one poster suggested in this thread, I would use the game controller model only allow the correct player to play. The GUI would reflect this by disabling all buttons that shouldn’t be pushed and only enabling the ones that should be pushed. How this is implemented in code depends on your current program’s code and overall structure.

    edit: addition to answer

    Not sure if you’re still around, but here’s a quickly slapped-together example of what I meant. The GamePlayer class represents (obviously) a player of the game and has a field, myTurn that is true only if it is that player’s turn, and this field has an associated void setMyTurn(boolean) method and a boolean isMyTurn() method.

    The GameModel class has an array of GamePlayer called players, a getPlayer(int) method that allows other classes to get each Player in the array, a playerTurnIndex that represents the index in the array of the player whose turn it currently is and a advancePlay() method that increments this index (mod’d by the length of the players array so it wraps around) and then loops through the players array setting the myTurn fields for each player depending on the playerTurnIndex value.

    The GameGui class had a GameModel field called gameModel and holds a collection of JButtons (actually a HashMap), and in each button’s ActionPerformed method, the model’s advancePlay() method is called and a private method called enablePlayerTurns() is called that enables or disables the player JButtons depending on the value of the corresponding player in the model:

    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.HashMap;
    import java.util.Map;
    
    import javax.swing.*;
    
    public class GamePlayMain {
        private static void createAndShowUI() {
            String[] players = {"John", "Bill", "Frank", "Henry"};
            GameModel model = new GameModel(players);
            GameGui gui = new GameGui(model);
    
            JFrame frame = new JFrame("GamePlayMain");
            frame.getContentPane().add(gui);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    createAndShowUI();
                }
            });
        }
    }
    
    class GamePlayer {
        private String name;
        private boolean myTurn = false;
    
        public GamePlayer(String name) {
            this.name = name;
        }
    
        public String getName() {
            return name;
        }
    
        public boolean isMyTurn() {
            return myTurn;
        }
    
        public void setMyTurn(boolean myTurn) {
            this.myTurn = myTurn;
        }
    
        @Override
        public String toString() {
            return name;
        }
    }
    
    class GameModel {
        private String[] playerNames;
        private GamePlayer[] players;
        private int playerTurnIndex = 0;
    
        public GameModel(String[] playerNames) {
            this.playerNames = playerNames;
            players = new GamePlayer[playerNames.length];
            for (int i = 0; i < playerNames.length; i++) {
                players[i] = new GamePlayer(playerNames[i]);
            }
            players[0].setMyTurn(true);
        }
    
        public int getPlayerTurnIndex() {
            return playerTurnIndex;
        }
    
        public GamePlayer getCurrentPlayer() {
            return players[playerTurnIndex];
        }
    
        public String[] getPlayerNames() {
            return playerNames;
        }
    
        public void advancePlay() {
            playerTurnIndex++;
            playerTurnIndex %= players.length;
            for (GamePlayer player : players) {
                if (player != getCurrentPlayer()) {
                    player.setMyTurn(false);
                } else {
                    player.setMyTurn(true);
                }
            }
        }
    
        public int getPlayerCount() {
            return players.length;
        }
    
        public GamePlayer getPlayer(int i) {
            return players[i];
        }
    
    }
    
    @SuppressWarnings("serial")
    class GameGui extends JPanel {
        private GameModel gameModel;
        private JTextArea textArea = new JTextArea(14, 30);
        private Map<GamePlayer, JButton> playerButtonMap = new HashMap<GamePlayer, JButton>();
    
        public GameGui(GameModel gameModel) {
            this.gameModel = gameModel;
    
            JPanel buttonPanel = new JPanel(new GridLayout(1, 0, 5, 0));
            for (int i = 0; i < gameModel.getPlayerCount(); i++) {
                GamePlayer player = gameModel.getPlayer(i);
                JButton playerButton = new JButton(player.getName());
                playerButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        playerButtonActionPerformed(e);
                    }
                });
                buttonPanel.add(playerButton);
                playerButtonMap.put(player, playerButton);
            }
    
            textArea.setEditable(false);
            textArea.setFocusable(false);
    
            setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
            setLayout(new BorderLayout(5, 5));
            add(buttonPanel, BorderLayout.NORTH);
            JScrollPane scrollPane = new JScrollPane(textArea);
            scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
            add(scrollPane, BorderLayout.CENTER);
    
            enablePlayerTurns();
        }
    
        private void playerButtonActionPerformed(ActionEvent e) {
            GamePlayer currentPlayer = gameModel.getCurrentPlayer();
    
            // TODO: have player "play"
            textArea.append("Player " + currentPlayer + " has just played\n");
            gameModel.advancePlay();
            enablePlayerTurns();
    
            currentPlayer = gameModel.getCurrentPlayer();
            textArea.append("It is now player " + currentPlayer + "'s turn\n");
        }
    
        private void enablePlayerTurns() {
            for (int i = 0; i < gameModel.getPlayerCount(); i++) {
                GamePlayer player = gameModel.getPlayer(i);
                JButton playerButton = playerButtonMap.get(player);
                playerButton.setEnabled(player.isMyTurn());
                if (player.isMyTurn()) {
                    playerButton.requestFocusInWindow();
                }
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, there is problem - I have the order to write web-app on Kohana
I have problem with items order in legend, when I using Google Chrome browser
I have some problem to order an array by a field of this, here
i have a problem to order a list by certain rule. Actually i have
I have problem with SQL query. If given order contains items, witch does not
I have a strange problem, I am trying to order the output of a
i have a problem about getting order of my divs. Scenario : i have
I am using Elixir for ORM but I have a problem trying to Order
I have two tables that I'm querying from. In one table, there are fields
I have a query that spits out a result: Select Sum(Count(P.Create_Dtime)), From Player P

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.