package Lec10;
import java.awt.*;
import java.awt.event.*;
import java.util.*; //課題2で追加
import javax.swing.*;
class MyMouseSample03
extends JPanel { //課題2で変更
java.util.List<Point> pointList = new LinkedList<Point>(); //課題2で追加
int xPanelSize;
int yPanelSize;
int x, y;
//コンストラクタ
MyMouseSample03(int xPanelSize, int yPanelSize) { //課題2で変更
this.xPanelSize = xPanelSize;
this.yPanelSize = yPanelSize;
addMouseMotionListener(new MyMouseMotionListener());
addMouseListener(new MyMouseActionListener());
}
x = evt.getX();
y = evt.getY();
System.
out.
println("( " + x
+ " , " + y
+ " )");
repaint();
}
}
private int clickNumber = 0;
clickNumber++;
System.
out.
println("( " + evt.
getX() + " , " + evt.
getY() + " ) " + clickNumber
+ "回目のクリック");
//課題2で追加
pointList.add(evt.getPoint());
repaint();
}
}
protected void paintComponent
(Graphics g
) { super.paintComponent(g);
size = getSize();
g.fillRect(0, 0, size.width, size.height);
//課題2で追加
Iterator<Point> it = pointList.iterator();
while (it.hasNext()) {
g.fillOval(p.x - 5, p.y - 5, 10, 10);
}
g.drawLine(x, 0, x, size.height);
g.drawLine(0, y, size.width, y);
}
public static void main
(String[] args
) { MyMouseSample03 panel = new MyMouseSample03(500, 400); //課題2で変更
panel.
setPreferredSize(new Dimension(panel.
xPanelSize, panel.
yPanelSize));
//JFrame fr = new JFrame();
//MyMenuFrame02 fr = new MyMenuFrame02("MyMouseSample01");
MyMenuFrame03 fr = new MyMenuFrame03("MyMouseSample03"); //課題2で変更
fr.add(panel);
fr.pack();
fr.setVisible(true);
}
}
cGFja2FnZSBMZWMxMDsKCmltcG9ydCBqYXZhLmF3dC4qOwppbXBvcnQgamF2YS5hd3QuZXZlbnQuKjsKaW1wb3J0IGphdmEudXRpbC4qOyAgLy/oqrLpoYwy44Gn6L+95YqgCmltcG9ydCBqYXZheC5zd2luZy4qOwoKY2xhc3MgTXlNb3VzZVNhbXBsZTAzIGV4dGVuZHMgSlBhbmVsIHsgIC8v6Kqy6aGMMuOBp+WkieabtAoK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ZvaWQgbW91c2VDbGlja2VkKE1vdXNlRXZlbnQgZXZ0KSB7CiAgICAgICAgICAgIGNsaWNrTnVtYmVyKys7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiKCAiICsgZXZ0LmdldFgoKSArICIgLCAiICsgZXZ0LmdldFkoKSArICIgKSAiICsgY2xpY2tOdW1iZXIgKyAi5Zue55uu44Gu44Kv44Oq44OD44KvIik7CgogICAgICAgICAgICAvL+iqsumhjDLjgafov73liqAKICAgICAgICAgICAgcG9pbnRMaXN0LmFkZChldnQuZ2V0UG9pbnQoKSk7CiAgICAgICAgICAgIHJlcGFpbnQoKTsKICAgICAgICB9CiAgICB9CgogICAgcHJvdGVjdGVkIHZvaWQgcGFpbnRDb21wb25lbnQoR3JhcGhpY3MgZykgewogICAgICAgIHN1cGVyLnBhaW50Q29tcG9uZW50KGcpOwoKICAgICAgICBzaXplID0gZ2V0U2l6ZSgpOwoKICAgICAgICBnLnNldENvbG9yKENvbG9yLkJMQUNLKTsKICAgICAgICBnLmZpbGxSZWN0KDAsIDAsIHNpemUud2lkdGgsIHNpemUuaGVpZ2h0KTsKCiAgICAgICAgLy/oqrLpoYwy44Gn6L+95YqgCiAgICAgICAgSXRlcmF0b3I8UG9pbnQ+IGl0ID0gcG9pbnRMaXN0Lml0ZXJhdG9yKCk7CiAgICAgICAgd2hpbGUgKGl0Lmhhc05leHQoKSkgewogICAgICAgICAgICBQb2ludCBwID0gKFBvaW50KSBpdC5uZXh0KCk7CgogICAgICAgICAgICBnLnNldENvbG9yKENvbG9yLkJMVUUpOwogICAgICAgICAgICBnLmZpbGxPdmFsKHAueCAtIDUsIHAueSAtIDUsIDEwLCAxMCk7CiAgICAgICAgfQoKICAgICAgICBnLnNldENvbG9yKENvbG9yLkdSRUVOKTsKICAgICAgICBnLmRyYXdMaW5lKHgsIDAsIHgsIHNpemUuaGVpZ2h0KTsKICAgICAgICBnLmRyYXdMaW5lKDAsIHksIHNpemUud2lkdGgsIHkpO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