-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrollButtonListener.java
More file actions
61 lines (53 loc) · 1.99 KB
/
TrollButtonListener.java
File metadata and controls
61 lines (53 loc) · 1.99 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
61
/**
* 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
*/
/**
* |-----------------------------------------------------------|
* | TrollButtonListener |
* |-----------------------------------------------------------|
* | Responsibilities | Collaborating Classes |
* |-------------------------------+---------------------------|
* | Instruct what to do when | TrollButton |
* | a troll 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 TrollButtonListener implements ActionListener
{
private TrollButton button;
private LastMovePanel lastMove;
private GameFieldPanel field;
// Purpose: Constructor takes in a troll button, info panel, and last move panel to reference.
public TrollButtonListener(TrollButton inputButton, GameFieldPanel inputField,
LastMovePanel inputLastMove)
{
button = inputButton;
lastMove = inputLastMove;
field = inputField;
}
/* Purpose: When clicked, a Troll Button will:
* show troll icon, become unclickable, decrement the number of tries on the info panel, set found treasures
* to 0, and update the last move panel.
*/
public void actionPerformed(ActionEvent e)
{
button.setEnabled(false);
lastMove.troll();
field.foundTroll();
}
}