-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLocationTab.java
More file actions
93 lines (69 loc) · 2.16 KB
/
LocationTab.java
File metadata and controls
93 lines (69 loc) · 2.16 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
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
/**
* LocationTab.java
* This class provides the GUI for one tab of a tabbed pane. This tab contains the player character's current situation
* and their options of where to go next.
* @author Emma Shumadine, Lily Orth-Smith, Rachel Zhang (primary)
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LocationTab extends JPanel
{
private JComboBox MoveCombo;
private JButton GoButton;
private JLabel DescriptionLabel, ErrorLabel;
private JPanel TopPanel, LowerPanel;
private String[] directions;
private Game g;
/**
* Creates the tab
* @param g the game associated with this tab
*/
public LocationTab(Game g) //pass Game g
{
setLayout(new GridLayout(2,0));
this.g = g;
DescriptionLabel = new JLabel (g.getCurrentDescription());
ErrorLabel = new JLabel("");
directions = g.getAdjNames();
MoveCombo = new JComboBox (directions);
GoButton = new JButton("Go");
TopPanel = new JPanel();
TopPanel.setBackground(new Color(200, 200, 244));
LowerPanel = new JPanel();
TopPanel.add(DescriptionLabel);
LowerPanel.add (MoveCombo);
LowerPanel.add (GoButton);
LowerPanel.add (ErrorLabel);
add(TopPanel);
add(LowerPanel);
GoButton.addActionListener(new ButtonListener());
}
private class ButtonListener implements ActionListener
{
private int current;
public void actionPerformed (ActionEvent event)
{
current = MoveCombo.getSelectedIndex();
if (current == 0)
ErrorLabel.setText("Please select a place to go to.");
else {
try {
ErrorLabel.setText("");
g.movePlayer(current-1);
if (g.hasFight()) {
g.startFight();
}
DescriptionLabel.setText(g.getCurrentDescription());
directions = g.getAdjNames();
MoveCombo.removeAllItems();
for (int j = 0; j < directions.length; j++)
MoveCombo.addItem(directions[j]);
}
catch (IllegalMoveException e) {
ErrorLabel.setText("Not enough memes.");
}
}
}
}
}