public interface StudentIface {
public int x=100;
public int y=100;
public int L=10;
public int R=10;
public int SIZE=40;
}
创建一个监听器继承鼠标监听器,设置画笔的方法,使得监听器调用的画笔对象赋值给申明的对象
public class StudentLisenter implements MouseListener {
Graphics graphics;
public void setGraphics(Graphics graphics){
this.graphics=graphics;
System.out.println(graphics+"g");
}
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
count++;
for (int i = 0; i < SIZE; i++) {
if (count % 2 == 1) {
graphics.setColor(Color.BLACK);
graphics.fillOval(x, y, 20, 20);
} else {
graphics.setColor(Color.WHITE);
graphics.fillOval(x, y, 20, 20);
}
}
}