import java.awt.*;
import java.awt.event.*;
import java.awt.event.MouseAdapter;
import java.math.BigDecimal;
import javax.swing.*;
public class ChessWZQ{
private JPanel panel; private JButton A;
private JTextField tf;
    private FlowLayout fl;
public static void main(String arg[]){
JFrame f=new JFrame("W  Z  Q");
f.setSize(500,500);
f.setVisible(true);
chessboard CB=new chessboard(14);
f.add(CB);
JButton A=new JButton("31465");
JTextField tf=new JTextField(30);
CB.addMouseListener(new ChessWZQmouseAdapter(CB));
JPanel panel=new JPanel();
FlowLayout fl=new FlowLayout();
f.show(); }
}class chessboard extends JPanel {
public void paint(Graphics gc){
super.paint(gc);
gc.setColor(Color.blue);
for(int i=0;i<15;i++){
gc.drawLine(30, 30+i*30, 450, 30+i*30);
gc.drawLine(30+i*30, 30, 30+i*30, 450);
}
gc.drawLine(25, 25, 455, 25);
gc.drawLine(25, 25, 25, 455);
gc.drawLine(25, 455, 455, 455);
gc.drawLine(455, 25, 455, 455);
for(int i=0;i<15;i++){
for(int j=0;j<15;j++){
int xp=16+i*30;
int yp=16+j*30;
if(conseat[i+1][j+1].nothing==1&&player==1){
gc.setColor(Color.black);
gc.fillOval(xp, yp, 28, 28);
}
if(conseat[i+1][j+1].nothing==1&&player==0){
gc.setColor(Color.white);
gc.fillOval(xp, yp, 28, 28);
}
}
}

}

public chessboard(int Format){
format=Format;
conseat=new seat[Format+3][Format+3];
for(int i=0;i<Format+3;i++){
for(int j=0;j<Format+3;j++){
seat S=new seat();
conseat[i][j]=S;
}
}
}
public int getformat(){
return format;
}
public int setformat(int Format){
return this.format=Format;
}
public void turn(){
player=Math.abs(player-1);
}
public void chessMouseClicked(MouseEvent e){
float x=0,y=0;
BigDecimal m,n;
int i, j;
x=e.getX();
y=e.getY();
m=new BigDecimal("x/30").setScale(0, BigDecimal.ROUND_HALF_UP); 
n=new BigDecimal("y/30").setScale(0, BigDecimal.ROUND_HALF_UP); 
i=m.intValue();
j=n.intValue();
if(x>20&&x<460&&y>20&&y<460&&(x%30<10||x%30>20)&&(y%30<10)||y%30>20){
return;
}
conseat[i][j].setadscription(this, i, j);
}
private int format;
public int player=1;
public seat[][] conseat;
}
public class ChessWZQmouseAdapter extends MouseAdapter {
public chessboard adaptee;
ChessWZQmouseAdapter(chessboard adaptee){
this.adaptee=adaptee;
}
public void mouseClicked(MouseEvent e){
adaptee.chessMouseClicked(e);
}}以上部分是相关内容的代码,主要关于事件的。望哪位师兄能看下指点一下,先谢过
我将chessboard类的CB添加一个监听器(ChessWZQmouseAdapter适配器来实现),ChessWZQmouseAdapter的执行程序是用的在chessboard类中定义的chessMouseClicked。但我运行时一旦在CB上点击鼠标就出现
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException
at java.math.BigDecimal.<init>(Unknown Source)
at java.math.BigDecimal.<init>(Unknown Source)
at chessboard.chessMouseClicked(chessboard.java:61)
at ChessWZQmouseAdapter.mouseClicked(ChessWZQmouseAdapter.java:9)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)