0

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.

Seeker
  • 509
  • 4
  • 19
  • It's not clear for me, 1) How an user enter to you app? Do you know if you open 2 jar 2 jvm instances are created then they don't share resources, so you have to persist user data in another way. – nachokk Feb 19 '14 at 19:40
  • 1) For better help sooner, post a [MCTaRE](http://stackoverflow.com/help/mcve) (Minimal Complete Tested and Readable Example). 2) Provide ASCII art (or an image with a simple drawing) of the GUI as it should appear in smallest size and (if resizable) with extra width/height. – Andrew Thompson Feb 19 '14 at 22:41
  • @AndrewThompson how do I upload an image? – Seeker Feb 20 '14 at 10:32

1 Answers1

2

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • How do you know that users takes a turn? they share the same gui? – nachokk Feb 19 '14 at 20:17
  • @nachokk `basically right now the user 1 goes first then user 2 and it repeats until the user/s quit the program.` The simplest implication is that they are using the same JVM/GUI. You're right that it could be interpreted differently as well. – Nick Rippe Feb 19 '14 at 20:52