-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreasureButton.java
More file actions
60 lines (52 loc) · 1.89 KB
/
TreasureButton.java
File metadata and controls
60 lines (52 loc) · 1.89 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/12/2022
*/
/**
* |-----------------------------------------------------------|
* | TreasureButton |
* |-----------------------------------------------------------|
* | Responsibilities | Collaborating Classes |
* |-------------------------------+---------------------------|
* | Create button functions | TreasureButtonListener |
* | | |
* | | EmptyButton |
* | | GameFieldPanel |
* | Shows Treasure when picked | GameInfoPanel |
* |-------------------------------+---------------------------|
*/
// Required library imports for GUI and event listeners.
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class TreasureButton extends EmptyButton
{
private ImageIcon treasure = new ImageIcon("treasure.PNG");
private ImageIcon locked = new ImageIcon("locked.PNG");
private int pointsValue;
// Purpose: Constructor passes the info panel to the superclass and sets the disabled icon.
public TreasureButton(GameInfoPanel inputInfo)
{
super(inputInfo);
setDisabledIcon(treasure);
pointsValue = new Random().nextInt(3) + 1;
}
// Purpose: Determine how a disabled treasure button should be revealed at end game.
public void reveal()
{
setDisabledIcon(locked);
setBackground(Color.GREEN);
}
// Purpose: Simply return the buttons point value from 1 to 3.
public int getPointsValue()
{
return pointsValue;
}
}