-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControlPanel.java
55 lines (43 loc) · 1.22 KB
/
ControlPanel.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
//ControlPanel.java
//File for adding buttons to Panel
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ControlPanel extends JPanel{
private final int WIDTH = 800;
private final int HEIGHT = 450;
private JPanel panel = this;
//the various buttons
private JButton next, reset, undo;
//constuctor; appearance of panel
public ControlPanel(){
panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
panel.setBackground(Color.white);
ActionListener listener = new ControlListener();
next = new JButton("Submit");
next.addActionListener(listener);
reset = new JButton("Reset Game");
reset.addActionListener(listener);
undo = new JButton("Undo Move");
undo.addActionListener(listener);
panel.add(next);
panel.add(reset);
panel.add(undo);
}
private class ControlListener implements ActionListener {
//do the correct action for each button
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == next){
GameFrame.moveNext();
}
if (source == reset) {
GameFrame.reset();
}
if(source==undo){
GameFrame.undo();
}
}
}
}