WannaPlaypublic class WannaPlay extends Dialog implements OkCancelDialogDisplays the Dialog when a player has been challenged for a game
initiates a message to the server with the players response |
Fields Summary |
---|
ResourceBundle | res | Panel | dlgPanel | Button | yes | Button | no | String | pieceColor | String | opponent | String | opponentRating | String | myRating | int | gameTime | int | moveTime | String[] | parm | Label | timeControlLabel | GridLayout | dialogLayout | Panel | buttonBar | Label | text1 | Label | text2 | String | timeControl | Panel | panel1 | GridLayout | gridLayout1 | ChessViewer | dlgParent |
Constructors Summary |
---|
public WannaPlay(Frame parent, ChessViewer theapp, String[] parm)Constructor
param Frame parent The Frame of this dialogs parent
param ChessViewer theapp
param String[] parm the parsed message data from the Challenge message
super(parent,"",false);
setTitle(res.getString("FRESH_MEAT_"));
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
if (parm.length < 6)
System.out.println("WannaPlay expected six parameters, found " + parm.length);
dlgParent = theapp;
opponent = parm[2];
opponentRating = parm[3];
myRating = parm[5];
this.parm = parm;
try {
gameTime = Integer.parseInt(parm[0]);
moveTime = Integer.parseInt(parm[1]);
}
catch (NumberFormatException e) {}
timeControl = CVS.Insert(res.getString("TIME_CONTROL"),parm[0],parm[1]);
jbInit();
add(dlgPanel);
timeControlLabel.setText(timeControl);
Random color = new Random();
if (opponent.equals(dlgParent.opponentName))
if (opponent.equals(dlgParent.game.getPlayerW()))
pieceColor = "white";
else
pieceColor = "black";
else
if (color.nextInt() > 0)
pieceColor = "white";
else
pieceColor = "black";
if (pieceColor.equals("white")) {
dlgParent.yourColor = ChessRules.White;
text2.setText(res.getString("YOU_GET_WHITE"));
}
else {
dlgParent.yourColor = ChessRules.Black;
text2.setText(res.getString("YOU_GET_BLACK"));
}
text1.setText(CVS.Insert(res.getString("DO_YOU_WANT_TO_PLAY"),opponent));
|
Methods Summary |
---|
public void | cancel(java.awt.event.ActionEvent evt)The OkCancelInterface method that the CancelButtonListener calls when its receives an action
dlgParent.sendMsg("RefuseChallenge",pieceColor) ;
dlgParent.opponentName = null;
// synchronized (dlgParent){
// dlgParent.notify();
// }
dispose();
| private void | jbInit()
dialogLayout.setRows(4);
dialogLayout.setColumns(1);
gridLayout1.setHgap(6);
buttonBar.setLayout(gridLayout1);
dlgPanel.setLayout(dialogLayout);
dlgPanel.add(text1);
dlgPanel.add(text2);
timeControlLabel.setText(res.getString("TIME_CONTROL"));
text2.setText(res.getString("YOU_GET_BLACK"));
text1.setText(res.getString("DO_YOU_WANT_TO_PLAY") );
dlgPanel.add(timeControlLabel);
dlgPanel.add(panel1, null);
panel1.add(buttonBar);
buttonBar.add(yes);
buttonBar.add(no);
yes.setLabel(res.getString("YES"));
yes.addActionListener(new OkButtonListener(this));
no.setLabel(res.getString("NO"));
no.addActionListener(new CancelButtonListener(this));
| public void | ok(java.awt.event.ActionEvent evt)the OkCancelDialog method that the OkButtonListener calls when its receives an action
dlgParent.gameTimeValue = gameTime;
dlgParent.playerTime[0] = dlgParent.gameTimeValue * 60000;
dlgParent.playerTime[1] = dlgParent.playerTime[0];
dlgParent.lMoveTime = moveTime * 1000;
parm[0] = pieceColor;
dlgParent.sendMsg("GameAccept",parm);
dlgParent.opponentName = opponent;
if (dlgParent.yourColor == ChessRules.White) {
dlgParent.newGame(dlgParent.myName,opponent);
dlgParent.statusLine.setText(res.getString("YOUR_MOVE"));
dlgParent.game.setWhiteElo(myRating);
dlgParent.game.setBlackElo(opponentRating);
}
else {
dlgParent.newGame(opponent,dlgParent.myName);
dlgParent.statusLine.setText(CVS.Insert(res.getString("WAITING_FOR"),dlgParent.game.getPlayerW()) );
dlgParent.game.setWhiteElo(opponentRating);
dlgParent.game.setBlackElo(myRating);
}
dlgParent.game.setSite(res.getString("BORLAND_CHESS_CLUB"));
dlgParent.game.setRound("-");
dlgParent.game.setEvent(res.getString("RATED_GAME"));
GregorianCalendar today = new GregorianCalendar();
dlgParent.game.setDate(String.valueOf(today.get(Calendar.YEAR))+ "." +
String.valueOf(today.get(Calendar.MONTH)+1) + "." +
String.valueOf(today.get(Calendar.DAY_OF_MONTH)));
dispose();
| protected void | processWindowEvent(java.awt.event.WindowEvent e)So System Close acts like pressing No
if (e.getID() == WindowEvent.WINDOW_CLOSING)
cancel(null);
else
super.processWindowEvent(e);
|
|