20130508【Java】マウスでクリックした座標を得る
お題
マウスでクリックした座標を得て、そこに円を描く
ソース
import java.awt.*;
public class MouseDownSample extends java.applet.Applet {
int xpos = 0;
int ypos = 0;
public void init() {
setForeground(Color.red);
}
public boolean mouseDown(Event e, int x, int y) {
xpos = x;
ypos = y;
repaint();
return true;
}
public void paint(Graphics g) {
g.fillOval(xpos, ypos, 30, 30);
}
}
実行結果
