home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1998 October A
/
Pcwk10a98.iso
/
Inprise
/
TRIAL
/
JBUILDER
/
JSAMPLES.Z
/
DrawDlg.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
4KB
|
126 lines
/*
* Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
*
* This SOURCE CODE FILE, which has been provided by Borland as part
* of a Borland product for use ONLY by licensed users of the product,
* includes CONFIDENTIAL and PROPRIETARY information of Borland.
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
* OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
* THE PRODUCT.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
* COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
* OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
* OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
* OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
* OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
* CODE FILE.
*/
package borland.samples.apps.chess.client;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
/**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{
ResourceBundle res = ResourceBundle.getBundle("borland.samples.apps.chess.client.Res");
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(res.getString("WANNA_DRAW_"));
}
else {
setTitle(res.getString("WANNA_ABORT_"));
drawdlg = false;
}
jbInit();
add(dlgPanel);
if (drawdlg)
text1.setText(dlgParent.opponentName + res.getString("HAS_OFFERED_YOU_A"));
else
text1.setText(dlgParent.opponentName + res.getString("HAS_OFFERED_TO_ABORT"));
}
private void jbInit() {
text1.setText(res.getString("HAS_OFFERED_YOU_A"));
text2.setText(res.getString("DO_YOU_ACCEPT_"));
dlgPanel.setLayout(dialogLayout);
eastSpace.setText(" ");
centerpanelLayout.setRows(3);
centerpanelLayout.setColumns(1);
westSpace.setText(" ");
northSpace.setText(" ");
dlgPanel.add(eastSpace,BorderLayout.EAST);
dlgPanel.add(westSpace,BorderLayout.WEST);
dlgPanel.add(northSpace,BorderLayout.NORTH);
dlgPanel.add(centerPanel,BorderLayout.CENTER);
centerPanel.setLayout(centerpanelLayout );
centerPanel.add(text1 );
centerPanel.add(text2);
buttonBar.add(yesButton);
yesButton.setLabel(res.getString("YES"));
buttonBar.add(noButton );
noButton.setLabel(res.getString("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(res.getString("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(res.getString("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);
}
}