我有这样一段程序:importjava.awt.*;importjava.awt.event.*;importjava.util.*;classFiveChessextendsCanvas{LinkedListblacklist=newLinkedList();LinkedListblacklist1=newLinked...
我有这样一段程序:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class FiveChess extends Canvas
{
LinkedList blacklist = new LinkedList();
LinkedList blacklist1 = new LinkedList();
int count1=0;
int c,c1,r1;
void init(){
this.winner();
this.addListener();
this.setSize(500,500);
this.setBackground(Color.yellow);
}
public void paint(Graphics g){
for(int x=0;x<=500;x=x+20){
g.drawLine(x,0,x,500);
}
for(int y=0;y<=500;y=y+20){
g.drawLine(0,y,500,y);
}
for (int i = 0;i < blacklist.size() ; i++)
{
if(i%2 ==0){
g.setColor(Color.black);
}
else{
g.setColor(Color.white);
}
Block b = (Block)blacklist.get(i);
g.fillOval(b.x,b.y,20,20);
}
}
void addListener(){
this.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
count1++;
int x = e.getX();
if((x/10)%2 == 0){
x = (x/10)*10 -10;
}
else{
x = (x/10)*10;
}
c1=x/10;
int y = e.getY();
if((y/10)%2 == 0){
y = (y/10)*10 - 10;
}
else{
y = (y/10)*10;
}
r1=y/10;
Block b = new Block(x,y);
blacklist.add(b);
repaint();
}
});
}
void winner(){
}
public static void main(String[] a){
Frame f=new Frame();
FiveChess ca=new FiveChess();
f.add(ca);
f.setBackground(Color.gray);
f.setLayout(new FlowLayout());
f.setSize(600,600);
f.setVisible(true);
ca.init();
}
}
可以运行处结果,但中间判断胜负的方法没写,请高手指教
展开