class ChessBoard extends Panel{
private Image imgBoard,imgBQizi,imgWQizi,imgBlank;
private ChessVector black=new ChessVector(),white=new ChessVector();
private int oldCsXx=-100,oldCsYy=-100, csX, csY;
private boolean placed=false;
private static int BWIDTH=1,BHEIGHT=1,GWIDTH=1,GHEIGHT=1,X0=1,Y0=1;
public ChessBoard(URLdo
cBase){
URL url1=null,url2=null,url3=null,url4=null;
//Timer t=new Timer(200,this);
//t.start();
try
{
url1=new URL(docBase,"qipan.jpg");
url2=new URL(docBase,"bchess.jpg");
url3=new URL(docBase,"wchess.jpg");
url4=new URL(docBase,"blank.jpg");
}catch (Exception e)
{
}
imgBoard=Toolkit.getDefaultToolkit().getImage(url1);
imgBQizi=Toolkit.getDefaultToolkit().getImage(url2);
imgWQizi=Toolkit.getDefaultToolkit().getImage(url3);
imgBlank=Toolkit.getDefaultToolkit().getImage(url4);
X0=20;
Y0=21;
BWIDTH=imgBoard.getWidth(null)-2*X0;
BHEIGHT=imgBoard.getHeight(null)-2*Y0;
GWIDTH=BWIDTH/15+2;
GHEIGHT=BHEIGHT/15+2;
}
public void paint(Graphics g){
g.drawImage(imgBoard,0,0,null);
}
}
public class WzqApplet extends Applet{
private InetAddress serveradd;
public void init(){
final ChessBoard chb=new ChessBoard(getDocumentBase());
setLayout(new BorderLayout());
add(chb,"Center");
}
我把代码精简了一下,基本上就这个样子了,请指教哟!