home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 October A / Pcwk10a98.iso / Inprise / TRIAL / JBUILDER / JSAMPLES.Z / DrawDlg.java < prev    next >
Text File  |  1998-05-08  |  4KB  |  126 lines

  1. /*
  2.  * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
  3.  * 
  4.  * This SOURCE CODE FILE, which has been provided by Borland as part
  5.  * of a Borland product for use ONLY by licensed users of the product,
  6.  * includes CONFIDENTIAL and PROPRIETARY information of Borland.  
  7.  *
  8.  * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 
  9.  * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
  10.  * THE PRODUCT.
  11.  *
  12.  * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
  13.  * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
  14.  * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
  15.  * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
  16.  * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
  17.  * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
  18.  * CODE FILE.
  19.  */
  20. package borland.samples.apps.chess.client;
  21.  
  22. import java.awt.*;
  23. import java.awt.event.ActionEvent;
  24. import java.awt.event.WindowEvent;
  25. import java.awt.event.ActionListener;
  26. import java.util.ResourceBundle;
  27.  
  28. /**Present the Draw dialog, and initiates the response to the server
  29. *  Does double duty as the Offer Abort dialog as well.
  30. */
  31. public class DrawDlg extends Dialog  implements OkCancelDialog{
  32.   ResourceBundle res = ResourceBundle.getBundle("borland.samples.apps.chess.client.Res");
  33.   Panel dlgPanel = new Panel();
  34.   Button yesButton = new Button();
  35.   Button noButton = new Button();
  36.   Label text1 = new Label();
  37.   Label text2 = new Label();
  38.   Panel centerPanel = new Panel();
  39.   Label northSpace  = new Label();
  40.   Label westSpace   = new Label();
  41.   Label eastSpace   = new Label();
  42.   BorderLayout dialogLayout = new BorderLayout();
  43.   boolean drawdlg;
  44.   Panel buttonBar = new Panel();
  45.   GridLayout centerpanelLayout = new GridLayout();
  46.   ChessViewer dlgParent;
  47.   
  48.   public DrawDlg(Frame parent,String name,ChessViewer theapp) {
  49.     super(parent,name,false);
  50.     enableEvents(AWTEvent.WINDOW_EVENT_MASK);
  51.     dlgParent = theapp;
  52.  
  53.     dlgParent.setModal(true);
  54.     if (name.equals("OfferDraw")) {
  55.       drawdlg = true;
  56.       setTitle(res.getString("WANNA_DRAW_"));
  57.     }
  58.     else {
  59.       setTitle(res.getString("WANNA_ABORT_"));
  60.       drawdlg = false;
  61.     }
  62.     jbInit();
  63.     add(dlgPanel);
  64.     if (drawdlg)
  65.       text1.setText(dlgParent.opponentName  + res.getString("HAS_OFFERED_YOU_A"));
  66.     else
  67.       text1.setText(dlgParent.opponentName  + res.getString("HAS_OFFERED_TO_ABORT"));
  68.   }
  69.   private void jbInit() {
  70.     text1.setText(res.getString("HAS_OFFERED_YOU_A"));
  71.     text2.setText(res.getString("DO_YOU_ACCEPT_"));
  72.     dlgPanel.setLayout(dialogLayout);
  73.     eastSpace.setText("  ");
  74.     centerpanelLayout.setRows(3);
  75.     centerpanelLayout.setColumns(1);
  76.     westSpace.setText("  ");
  77.     northSpace.setText("  ");
  78.     dlgPanel.add(eastSpace,BorderLayout.EAST);
  79.     dlgPanel.add(westSpace,BorderLayout.WEST);
  80.     dlgPanel.add(northSpace,BorderLayout.NORTH);
  81.     dlgPanel.add(centerPanel,BorderLayout.CENTER);
  82.     centerPanel.setLayout(centerpanelLayout );
  83.     centerPanel.add(text1 );
  84.     centerPanel.add(text2);
  85.     buttonBar.add(yesButton);
  86.     yesButton.setLabel(res.getString("YES"));
  87.     buttonBar.add(noButton );
  88.     noButton.setLabel(res.getString("NO"));
  89.     yesButton.addActionListener(new OkButtonListener(this));
  90.     noButton.addActionListener(new CancelButtonListener(this));
  91.     centerPanel.add(buttonBar);
  92.   }
  93.  
  94.   public void ok(ActionEvent evt) {
  95.     int i=1;
  96.  
  97.     if (drawdlg) {
  98.       dlgParent.statusLine.setText(res.getString("GAME_DRAWN"));
  99.       dlgParent.game.setComment(dlgParent.movecount,dlgParent.color,"1/2-1/2");
  100.       dlgParent.sendMsg("AcceptDraw","1/2-1/2")   ;
  101.       dlgParent.gameOver();
  102.       dlgParent.setModal(false);
  103.     }
  104.     else {
  105.       dlgParent.statusLine.setText(res.getString("GAME_ABORTED"));
  106.       dlgParent.sendMsg("AcceptAbort","Aborted")   ;
  107.     }
  108.     dlgParent.gameOver();
  109.     dlgParent.setModal(false);
  110.     dispose();
  111.   }
  112.  
  113.   protected void processWindowEvent(WindowEvent e)  {
  114.     if (e.getID() == WindowEvent.WINDOW_CLOSING)
  115.       cancel(null);
  116.     super.processWindowEvent(e);
  117.   }
  118.  
  119.   public void cancel(ActionEvent evt) {
  120.     dlgParent.sendMsg("Refused","") ;
  121.     dispose();
  122.     dlgParent.setModal(false);
  123.   }
  124. }
  125.  
  126.