-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmptyButtonListener.java
More file actions
60 lines (53 loc) · 1.95 KB
/
EmptyButtonListener.java
File metadata and controls
60 lines (53 loc) · 1.95 KB
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
/**
* Lead Author:
* Ian Kligman; 5550139764
*
* References:
* Gaddis, T. (2015). Starting Out With Java Myprogramming Lab
* From Control Structures Through Objects. (6th ed.). Addison-Wesley.
*
*
* Version: 12/7/2022
*/
/**
* |-----------------------------------------------------------|
* | EmptyButtonListener |
* |-----------------------------------------------------------|
* | Responsibilities | Collaborating Classes |
* |-------------------------------+---------------------------|
* | Instruct what to do when | EmptyButton |
* | an empty button is clicked | |
* | | LastMovePanel |
* | | GameFieldPanel |
* | | GameInfoPanel |
* |-------------------------------+---------------------------|
*/
// Required library imports for GUI and event listeners.
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.event.*;
public class EmptyButtonListener implements ActionListener
{
private EmptyButton button;
private LastMovePanel lastMove;
private GameFieldPanel field;
// Purpose: Constructor takes in an EmptyButton, GameInfoPanel, and LastMovePanel.
public EmptyButtonListener(EmptyButton inputButton, GameFieldPanel inputField,
LastMovePanel inputLastMove)
{
button = inputButton;
lastMove = inputLastMove;
field = inputField;
}
/* Purpose: When clicked, an Empty Button will:
* show empty icon, become unclickable, decrement the number of tries on the info panel
* and update the last move panel.
*/
public void actionPerformed(ActionEvent e)
{
button.setEnabled(false);
lastMove.fail();
field.reduceNumberOfTries();
}
}