1: package ;
2:
3: import ;
4: import ;
5: import ;
6: import ;
7:
8: import ;
9: import ;
10: import ;
11: import ;
12: import ;
13: import ;
14: import ;
15:
16:
19: public class HumanPlayerInterface extends GameStateFrame
20:
... {
21:
22:
23:
24:
protected SimplePropertyChangeSupport pcs;
25:
26:
27:
28:
31:
public HumanPlayerInterface(Player player, GameState gamestate, final IExternalAccess agent)
32:
... {
33:
super(gamestate, null);
34:
setControlPanel(new HumanPlayerControlPanel(player, gamestate));
35:
pcs = new SimplePropertyChangeSupport(this);
36:
37:
38:
addWindowListener(new WindowAdapter()
39:
... {
40:
public void windowClosing(WindowEvent e)
41:
... {
42:
agent.killAgent();
43:
}
44:
});
45:
46:
47:
agent.addAgentListener(new IAgentListener()
48:
... {
49:
public void agentTerminating(AgentEvent e)
50:
... {
51:
SwingUtilities.invokeLater(new Runnable()
52:
... {
53:
public void run()
54:
... {
55:
HumanPlayerInterface.this.dispose();
56:
}
57:
});
58:
}
59:
}, false);
60:
61:
this.setTitle("Human player: "+player.getName());
62:
this.pack();
63:
this.setLocation(SGUI.calculateMiddlePosition(this));
64:
this.setVisible(true);
65:
}
66:
67:
68:
69:
74:
public void addPropertyChangeListener(PropertyChangeListener listener)
75:
... {
76:
pcs.addPropertyChangeListener(listener);
77:
}
78:
79:
85:
public void removePropertyChangeListener(PropertyChangeListener listener)
86:
... {
87:
pcs.removePropertyChangeListener(listener);
88:
}
89:
90:
91:
94:
public class HumanPlayerControlPanel extends JPanel
95:
... {
96:
97:
protected JSpinner betsp;
98:
99:
100:
protected JButton betbut;
101:
102:
103:
protected JProgressBar betprogress;
104:
105:
106:
protected JButton draw;
107:
108:
109:
protected JButton stop;
110:
111:
112:
protected JProgressBar drawprogress;
113:
114:
115:
protected int bet;
116:
117:
118:
protected boolean drawcard;
119:
120:
121:
protected Timer timer;
122:
123:
126:
public HumanPlayerControlPanel(Player player, GameState gamestate)
127:
... {
128:
this.setLayout(new BorderLayout());
129:
130:
betsp = new JSpinner(new SpinnerNumberModel(10,1,100,1));
131:
betbut = new JButton(GUIImageLoader.getImage("bet"));
132:
betbut.addActionListener(new ActionListener()
133:
... {
134:
public void actionPerformed(ActionEvent e)
135:
... {
136:
makeBet();
137:
}
138:
});
139:
betbut.setEnabled(false);
140:
betprogress = new JProgressBar(0, 5);
141:
142:
draw = new JButton(GUIImageLoader.getImage("hit"));
143:
draw.addActionListener(new ActionListener()
144:
... {
145:
public void actionPerformed(ActionEvent e)
146:
... {
147:
148:
setDrawCard(true);
149:
}
150:
});
151:
draw.setEnabled(false);
152:
stop = new JButton(GUIImageLoader.getImage("stand"));
153:
stop.addActionListener(new ActionListener()
154:
... {
155:
public void actionPerformed(ActionEvent e)
156:
... {
157:
158:
setDrawCard(false);
159:
}
160:
});
161:
stop.setEnabled(false);
162:
drawprogress = new JProgressBar(0, 5);
163:
164:
JPanel control = new JPanel(new GridBagLayout());
165:
control.add(betprogress, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST,
166:
GridBagConstraints.BOTH, new Insets(2,2,2,2), 0, 0));
167:
control.add(betsp, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
168:
GridBagConstraints.HORIZONTAL, new Insets(2,2,2,2), 0, 0));
169:
control.add(betbut, new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
170:
GridBagConstraints.HORIZONTAL, new Insets(2,2,2,2), 0, 0));
171:
172:
control.add(drawprogress, new GridBagConstraints(0, 2, 1, 1, 1, 0, GridBagConstraints.WEST,
173:
GridBagConstraints.BOTH, new Insets(2,2,2,2), 0, 0));
174:
control.add(draw, new GridBagConstraints(1, 2, 1, 1, 0, 0, GridBagConstraints.WEST,
175:
GridBagConstraints.HORIZONTAL, new Insets(2,2,2,2), 0, 0));
176:
control.add(stop, new GridBagConstraints(2, 2, 1, 1, 0, 0, GridBagConstraints.WEST,
177:
GridBagConstraints.HORIZONTAL, new Insets(2,2,2,2), 0, 0));
178:
179:
184:
Dimension d = new Dimension(50,30);
185:
betsp.setMaximumSize(d);
186:
betsp.setPreferredSize(d);
187:
betbut.setMinimumSize(d);
188:
betbut.setPreferredSize(d);
189:
draw.setMinimumSize(d);
190:
draw.setPreferredSize(d);
191:
stop.setMinimumSize(d);
192:
stop.setPreferredSize(d);
193:
194:
this.add("Center", new PlayerPanel(player));
195:
this.add("South", control);
196:
}
197:
198:
201:
protected void makeBet()
202:
... {
203:
try
204:
... {
205:
setBet(((Integer)betsp.getValue()).intValue());
206:
207:
}
208:
catch(NumberFormatException ne)
209:
... {
210:
211:
}
212:
}
213:
214:
217:
public void enableBid()
218:
... {
219:
220:
betbut.setEnabled(true);
221:
222:
betprogress.setValue(5);
223:
betprogress.setString(betprogress.getValue()+" sec left");
224:
betprogress.setStringPainted(true);
225:
timer = new Timer(1000, null);
226:
ActionListener al = new ActionListener()
227:
... {
228:
public void actionPerformed(ActionEvent e)
229:
... {
230:
int time = betprogress.getValue()-1;
231:
betprogress.setValue(betprogress.getValue()-1);
232:
betprogress.setString(time+" sec left");
233:
if(betprogress.getValue()==0)
234:
... {
235:
timer.stop();
236:
makeBet();
237:
}
238:
}
239:
};
240:
timer.addActionListener(al);
241:
timer.start();
242:
}
243:
244:
247:
public void disableBid()
248:
... {
249:
250:
betbut.setEnabled(false);
251:
252:
timer.stop();
253:
betprogress.setValue(0);
254:
betprogress.setStringPainted(false);
255:
}
256:
257:
260:
public void enableDrawCard()
261:
... {
262:
263:
264:
draw.setEnabled(true);
265:
stop.setEnabled(true);
266:
drawprogress.setValue(5);
267:
drawprogress.setString(drawprogress.getValue()+" sec left");
268:
drawprogress.setStringPainted(true);
269:
timer = new Timer(1000, null);
270:
ActionListener al = new ActionListener()
271:
... {
272:
public void actionPerformed(ActionEvent e)
273:
... {
274:
int time = drawprogress.getValue()-1;
275:
drawprogress.setString(time+" sec left");
276:
drawprogress.setValue(time);
277:
if(drawprogress.getValue()==0)
278:
timer.stop();
279:
}
280:
};
281:
timer.addActionListener(al);
282:
timer.start();
283:
}
284:
285:
288:
public void disableDrawCard()
289:
... {
290:
291:
292:
draw.setEnabled(false);
293:
stop.setEnabled(false);
294:
timer.stop();
295:
drawprogress.setValue(0);
296:
drawprogress.setStringPainted(false);
297:
}
298:
299:
302:
public int getBet()
303:
... {
304:
return bet;
305:
}
306:
307:
311:
public void setBet(int bet)
312:
... {
313:
this.bet = bet;
314:
pcs.firePropertyChange("new_bet", null, new Integer(bet));
315:
}
316:
317:
321:
public boolean isDrawCard()
322:
... {
323:
return drawcard;
324:
}
325:
326:
330:
public void setDrawCard(boolean drawcard)
331:
... {
332:
this.drawcard = drawcard;
333:
pcs.firePropertyChange("new_drawcard", null, new Boolean(drawcard));
334:
}
335:
336:
337:
}
338:
}