-
Notifications
You must be signed in to change notification settings - Fork 0
/
RPSKLCreatorButtonSet.java
103 lines (86 loc) · 2.73 KB
/
RPSKLCreatorButtonSet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* This Class creates Jbuttons that creates each move of R P S K and L. It
* utilizes MouseListener to receive user input. This Class was inspired by
* Observer pattern example provided in Coursework.
*
* @author ChangSu Nam
* @UNI cn2521
* @since Asssignment4 2.2
*
*/
public class RPSKLCreatorButtonSet extends JFrame {
/**
* Contructor that creates Jbuttons horizontaly, with MouseListeners.
*
* @param inputLabel the JLabel used for GUI.
*/
public RPSKLCreatorButtonSet(JLabel inputLabel) {
// g2d = new Graphics2D();
JPanel buttonPanel = new JPanel();
JButton rockButton = new JButton("R");
rockButton.setHorizontalAlignment(SwingConstants.LEFT);
JButton paperButton = new JButton("P");
paperButton.setHorizontalAlignment(SwingConstants.LEFT);
JButton scissorsButton = new JButton("S");
scissorsButton.setHorizontalAlignment(SwingConstants.LEFT);
JButton spockButton = new JButton("K");
spockButton.setHorizontalAlignment(SwingConstants.LEFT);
JButton lizardButton = new JButton("L");
lizardButton.setHorizontalAlignment(SwingConstants.LEFT);
rockButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
System.out.println("set move to rock");
playerMove = "rock";
BattleField.setMove(playerMove);
inputLabel.repaint();
}
});
paperButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
System.out.println("set move to paper");
playerMove = "paper";
BattleField.setMove(playerMove);
// inputLabel.update(inputLabel.getGraphics());
inputLabel.repaint();
}
});
scissorsButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
System.out.println("set move to scissors");
playerMove = "scissors";
BattleField.setMove(playerMove);
inputLabel.repaint();
}
});
spockButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
System.out.println("set move to spock");
playerMove = "spock";
BattleField.setMove(playerMove);
inputLabel.repaint();
}
});
lizardButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
System.out.println("set move to lizard");
playerMove = "lizard";
BattleField.setMove(playerMove);
inputLabel.repaint();
}
});
buttonPanel.add(rockButton);
buttonPanel.add(paperButton);
buttonPanel.add(scissorsButton);
buttonPanel.add(lizardButton);
buttonPanel.add(spockButton);
// buttonPanel.add(buttonLabel);
add(buttonPanel, BorderLayout.NORTH);
}
/**
* playerMove the value that reflects R,P,S,K or L to be played.
*/
private String playerMove;
}