-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathInventoryPanel.java
169 lines (134 loc) · 5.69 KB
/
InventoryPanel.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import java.util.*;
import greenfoot.core.WorldHandler;
import greenfoot.core.Simulation;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import greenfoot.*;
/**
* Write a description of class InventoryPanel here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class InventoryPanel
{
private InventoryItem inventoryItem;
/**
* Creates new form Canvas2
*/
public InventoryPanel() {
initComponents();
}
private void initComponents() {
final JPanel canvas = WorldHandler.getInstance().getWorldCanvas();
if(panel != null) {
panel.removeAll();
canvas.remove(panel);
}
layoutManager = canvas.getLayout();
canvas.setLayout(new javax.swing.BoxLayout(canvas, javax.swing.BoxLayout.LINE_AXIS));
itemsGroup = new javax.swing.ButtonGroup();
panel = new javax.swing.JPanel();
infoPanel = new javax.swing.JPanel();
pcPanel = new ImagePanel();
statsPanel = new JPanel();
itemsPanel = new javax.swing.JPanel();
itemButton = new javax.swing.JRadioButton();
controlsPanel = new javax.swing.JPanel();
useButton = new javax.swing.JButton();
exitButton = new javax.swing.JButton();
panel.setLayout(new java.awt.GridLayout(3, 1));
infoPanel.setLayout(new java.awt.GridLayout(1, 2));
javax.swing.GroupLayout pcPanelLayout = new javax.swing.GroupLayout(pcPanel);
pcPanel.setLayout(pcPanelLayout);
pcPanelLayout.setHorizontalGroup(
pcPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 200, Short.MAX_VALUE)
);
pcPanelLayout.setVerticalGroup(
pcPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 124, Short.MAX_VALUE)
);
infoPanel.add(pcPanel);
statsPanel.setAutoscrolls(true);
javax.swing.GroupLayout statsPanelLayout = new javax.swing.GroupLayout(statsPanel);
statsPanel.setLayout(statsPanelLayout);
statsPanelLayout.setHorizontalGroup(
statsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 200, Short.MAX_VALUE)
);
statsPanelLayout.setVerticalGroup(
statsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 124, Short.MAX_VALUE)
);
infoPanel.add(statsPanel);
panel.add(infoPanel);
itemsPanel.setAutoscrolls(true);
itemsPanel.setLayout(new javax.swing.BoxLayout(itemsPanel, javax.swing.BoxLayout.PAGE_AXIS));
itemsGroup.add(itemButton);
itemButton.setText("Ahgof");
for(final InventoryItem item : Game.getInventory().getItems()) {
itemButton = new javax.swing.JRadioButton();
itemsGroup.add(itemButton);
itemButton.setText(item.getDescription());
itemButton.addActionListener(new java.awt.event.ActionListener() {
int i = 0;
public void actionPerformed(java.awt.event.ActionEvent evt) {
inventoryItem = item;
}
});
itemsPanel.add(itemButton);
}
panel.add(itemsPanel);
controlsPanel.setLayout(new javax.swing.BoxLayout(controlsPanel, javax.swing.BoxLayout.LINE_AXIS));
useButton.setText("use");
useButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
useButtonActionPerformed(evt);
}
});
controlsPanel.add(useButton);
exitButton.setText("exit");
exitButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitButtonActionPerformed(evt);
}
});
controlsPanel.add(exitButton);
panel.add(controlsPanel);
canvas.add(panel);
canvas.updateUI();
}// </editor-fold>
private void useButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Game.getInventory().use(inventoryItem);
}
private void itemButtonActionPerformed(java.awt.event.ActionEvent evt) {
}
private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
}
// Variables declaration - do not modify
private javax.swing.JPanel controlsPanel;
private javax.swing.JButton exitButton;
private javax.swing.JPanel infoPanel;
private javax.swing.JRadioButton itemButton;
private javax.swing.ButtonGroup itemsGroup;
private javax.swing.JPanel itemsPanel;
private javax.swing.JPanel panel;
private ImagePanel pcPanel;
private javax.swing.JPanel statsPanel;
private javax.swing.JButton useButton;
// End of variables declaration
private LayoutManager layoutManager;
public void dispose() {
final JPanel canvas = WorldHandler.getInstance().getWorldCanvas();
canvas.remove(panel);
canvas.setLayout(layoutManager);
canvas.updateUI();
canvas.requestFocus();
SceneManager.getInstance().resumeToActionWorld();
}
}