home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-07-03 | 3.1 KB | 105 lines |
- package borland.samples.apps.chess.client;
-
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.WindowEvent;
- import java.awt.event.ActionListener;
-
- /**Present the Draw dialog, and initiates the response to the server
- * Does double duty as the Offer Abort dialog as well.
- */
- public class DrawDlg extends Dialog implements OkCancelDialog{
- Panel dlgPanel = new Panel();
- Button yesButton = new Button();
- Button noButton = new Button();
- Label text1 = new Label();
- Label text2 = new Label();
- Panel centerPanel = new Panel();
- Label northSpace = new Label();
- Label westSpace = new Label();
- Label eastSpace = new Label();
- BorderLayout dialogLayout = new BorderLayout();
- boolean drawdlg;
- Panel buttonBar = new Panel();
- GridLayout centerpanelLayout = new GridLayout();
- ChessViewer dlgParent;
-
- public DrawDlg(Frame parent,String name,ChessViewer theapp) {
- super(parent,name,false);
- enableEvents(AWTEvent.WINDOW_EVENT_MASK);
- dlgParent = theapp;
-
- dlgParent.setModal(true);
- if (name.equals("OfferDraw")) {
- drawdlg = true;
- setTitle(CVS.WANNA_DRAW_);
- }
- else {
- setTitle(CVS.WANNA_ABORT_);
- drawdlg = false;
- }
- jbInit();
- add(dlgPanel);
- if (drawdlg)
- text1.setText(dlgParent.opponentName + CVS.HAS_OFFERED_YOU_A);
- else
- text1.setText(dlgParent.opponentName + CVS.HAS_OFFERED_TO_ABORT);
- }
- public void jbInit() {
- text1.setText(CVS.HAS_OFFERED_YOU_A);
- text2.setText(CVS.DO_YOU_ACCEPT_);
- dlgPanel.setLayout(dialogLayout);
- eastSpace.setText(" ");
- centerpanelLayout.setRows(3);
- centerpanelLayout.setColumns(1);
- westSpace.setText(" ");
- northSpace.setText(" ");
- dlgPanel.add(eastSpace,"East");
- dlgPanel.add(westSpace,"West");
- dlgPanel.add(northSpace,"North");
- dlgPanel.add(centerPanel,"Center");
- centerPanel.setLayout(centerpanelLayout );
- centerPanel.add(text1 );
- centerPanel.add(text2);
- buttonBar.add(yesButton);
- yesButton.setLabel(CVS.YES);
- buttonBar.add(noButton );
- noButton.setLabel(CVS.NO);
- yesButton.addActionListener(new OkButtonListener(this));
- noButton.addActionListener(new CancelButtonListener(this));
- centerPanel.add(buttonBar);
- }
-
- public void ok(ActionEvent evt) {
- int i=1;
-
- if (drawdlg) {
- dlgParent.statusLine.setText(CVS.GAME_DRAWN);
- dlgParent.game.setComment(dlgParent.movecount,dlgParent.color,"1/2-1/2");
- dlgParent.sendMsg("AcceptDraw","1/2-1/2") ;
- dlgParent.gameOver();
- dlgParent.setModal(false);
- }
- else {
- dlgParent.statusLine.setText(CVS.GAME_ABORTED);
- dlgParent.sendMsg("AcceptAbort","Aborted") ;
- }
- dlgParent.gameOver();
- dlgParent.setModal(false);
- dispose();
- }
-
- protected void processWindowEvent(WindowEvent e) {
- if (e.getID() == WindowEvent.WINDOW_CLOSING)
- cancel(null);
- super.processWindowEvent(e);
- }
-
- public void cancel(ActionEvent evt) {
- dlgParent.sendMsg("Refused","") ;
- dispose();
- dlgParent.setModal(false);
- }
- }
-
-