Reputation: 509
would it be possible to organise the text I have on my JTextArea for example.
JTextArea information = new JTextArea("User1Click: \nUser2Click");
JButton button = new JButton();
JButton button1 = new JButton();
JButton button2 = new JButton();
JButton button3 = new JButton();
button.setText(button);
button.setText(button1);
button.setText(button2);
button.setText(button3);
button.setText(button4);
right now, the JTextArea appears on the JFrame like this;
User1Click:
User2Click:
What I want to do is, basically right now the user 1 goes first then user 2 and it repeats until the user/s quit the program. So what I want to do is, everytime a user clicks a button ,depending on which user click it, I want the name of the button to appear after they specified field. for example.
User1Click: button1 button3 button1 button2
User2Click: button4 button2 button1 button2 button3
the example above shows that user 1 has clicked button1, 3 1 ad 2 and user2 has clicked button4, 2, 1, 2 and 3.
edited: sorry about the late reply. both users are on the same computer and user turn is counted by clicks, if for example click == 1 then its user 1 turn and if click == 2 then its user 2 turn, if click == 3 then its user 1 turn and if click == 4 then its user 2 turn and so on.
Upvotes: 0
Views: 104
Reputation: 205785
As shown here, you can use MVC to maintain a separate model of the turns taken. Let the model maintain a List<Integer>
of turns representing the history for each user. The JTextArea
that displays the history is then just another listening view. Each time a user takes a turn, the button's action listener updates the model, and the listening view(s) update themselves accordingly.
Upvotes: 2