419
|
1 package test.editortest;
|
|
2
|
|
3 import java.awt.FlowLayout;
|
|
4 import java.awt.event.ActionEvent;
|
|
5 import java.awt.event.ActionListener;
|
|
6 import java.util.LinkedList;
|
|
7
|
|
8 import javax.swing.JButton;
|
|
9 import javax.swing.JFrame;
|
|
10
|
|
11 import rep.REP;
|
|
12 import rep.REPCommand;
|
|
13
|
|
14 public class UserSimulator extends JFrame implements ActionListener{
|
|
15
|
|
16 /**
|
|
17 *
|
|
18 */
|
|
19 private static final long serialVersionUID = 1L;
|
|
20 private JButton startButton;
|
|
21 private LinkedList<SimpleEditorForREPEditor> editorList;
|
|
22 private JButton initButton;
|
|
23
|
|
24 public UserSimulator(String title){
|
|
25 super(title);
|
|
26
|
|
27 editorList = new LinkedList<SimpleEditorForREPEditor>();
|
|
28
|
|
29 setButton();
|
|
30 pack();
|
|
31 }
|
|
32
|
|
33 private void init(){
|
|
34 editorList.get(0).repPut();
|
|
35 for(int i = 1; i < editorList.size(); i++){
|
|
36 editorList.get(i).repJoin();
|
|
37 }
|
|
38 initButton.setEnabled(false);
|
|
39 }
|
|
40
|
|
41 private void setButton() {
|
|
42 setLayout(new FlowLayout());
|
|
43
|
|
44 initButton = new JButton("init");
|
|
45 startButton = new JButton("start");
|
|
46 add(initButton);
|
|
47 add(startButton);
|
|
48
|
|
49 initButton.addActionListener(this);
|
|
50 startButton.addActionListener(this);
|
|
51 }
|
|
52
|
|
53 public void add(SimpleEditorForREPEditor editor) {
|
|
54 editorList.add(editor);
|
|
55 }
|
|
56
|
|
57 public void actionPerformed(ActionEvent e) {
|
|
58 if(e.getSource() == startButton){
|
|
59 userStart();
|
|
60 }else if(e.getSource() == initButton){
|
|
61 init();
|
|
62 }
|
|
63 }
|
|
64
|
|
65 private void userStart() {
|
|
66 UserThread user = new UserThread();
|
|
67 user.start();
|
|
68 }
|
|
69
|
|
70 class UserThread extends Thread{
|
|
71 public void run(){
|
|
72 // for(REPCommand command : userInputList){
|
|
73 for(int i = 0; i < 5; i++){
|
|
74 for(SimpleEditorForREPEditor editor : editorList){
|
420
|
75 REPCommand command = new REPCommand(REP.REPCMD_INSERT_USER, 0, 0, 0, 0, editor.getTitle() + ":" + i);
|
419
|
76 ((REPTextWithJTextArea) editor.getREPEditor().getREPText()).userInsert(command);
|
|
77 }
|
|
78 }
|
|
79 }
|
|
80 }
|
|
81
|
|
82 }
|