home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 15
/
BUGCD1998_06.ISO
/
aplic
/
jbuilder
/
jsamples.z
/
PromotionDialog.java
< prev
next >
Wrap
Text File
|
1997-07-03
|
2KB
|
84 lines
package borland.samples.apps.chess.client.board;
import java.awt.*;
import java.awt.event.*;
public class PromotionDialog extends Dialog implements MouseListener {
PromotionCanvas pieceCanvas = new PromotionCanvas();
Chessboard dlgParent;
Image pieceImage;
public PromotionDialog(Frame parent,Image pieceimage,Chessboard theParent) {
super(parent,"Promote your pawn",false);
System.out.println("promotionDialog xtor");
dlgParent = theParent;
this.pieceImage = pieceimage;
jbInit();
setLayout(new FlowLayout());
}
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
if (d.width < 180)
return new Dimension(180,d.height);
else
return d;
}
public void jbInit() {
pieceCanvas.setImage(pieceImage);
pieceCanvas.addMouseListener(this);
add(pieceCanvas);
}
public void mouseClicked(MouseEvent parm1) {
// java.awt.event.MouseListener method;
}
public void mousePressed(MouseEvent parm1) {
// java.awt.event.MouseListener method;
int piecesub = parm1.getX() * 4 / pieceCanvas.pieces.getWidth(this);
if (piecesub > 3)
piecesub = 3;
dlgParent.promote(piecesub);
dispose();
}
public void mouseReleased(MouseEvent parm1) {
// java.awt.event.MouseListener method;
}
public void mouseEntered(MouseEvent parm1) {
// java.awt.event.MouseListener method;
}
public void mouseExited(MouseEvent parm1) {
// java.awt.event.MouseListener method;
}
}
class PromotionCanvas extends Canvas
{
Image pieces;
public PromotionCanvas(Image img) {
pieces = img;
}
public PromotionCanvas() {
}
public void setImage(Image img) {
pieces = img;
}
public Dimension getPreferredSize() {
return new Dimension(pieces.getWidth(this) , pieces.getHeight(this));
}
public void paint(Graphics g) {
g.drawImage(pieces,0,0,this);
}
}