package Lec10;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class MyMouseSample02
extends JPanel { //課題1で変更
int xPanelSize;
int yPanelSize;
int x, y;
//コンストラクタ
MyMouseSample02(int xPanelSize, int yPanelSize) { //課題1で変更
this.xPanelSize = xPanelSize;
this.yPanelSize = yPanelSize;
addMouseMotionListener(new MyMouseMotionListener());
addMouseListener(new MyMouseActionListener()); //課題1で追加
}
x = evt.getX();
y = evt.getY();
System.
out.
println("( " + x
+ " , " + y
+ " )");
repaint();
}
}
//課題1で追加
private int clickNumber = 0;
clickNumber++;
System.
out.
println("( " + evt.
getX() + " , " + evt.
getY() + " ) " + clickNumber
+ "回目のクリック"); }
}
protected void paintComponent
(Graphics g
) { super.paintComponent(g);
size = getSize();
g.fillRect(0, 0, size.width, size.height);
g.drawLine(x, 0, x, size.height);
g.drawLine(0, y, size.width, y);
}
public static void main
(String[] args
) { MyMouseSample02 panel = new MyMouseSample02(500, 400); //課題1で変更
panel.
setPreferredSize(new Dimension(panel.
xPanelSize, panel.
yPanelSize));
//JFrame fr = new JFrame();
//MyMenuFrame02 fr = new MyMenuFrame02("MyMouseSample01");
MyMenuFrame03 fr = new MyMenuFrame03("MyMouseSample02"); //課題1で変更
fr.add(panel);
fr.pack();
fr.setVisible(true);
}
}
cGFja2FnZSBMZWMxMDsKCmltcG9ydCBqYXZhLmF3dC4qOwppbXBvcnQgamF2YS5hd3QuZXZlbnQuKjsKaW1wb3J0IGphdmF4LnN3aW5nLio7CgpjbGFzcyBNeU1vdXNlU2FtcGxlMDIgZXh0ZW5kcyBKUGFuZWwgeyAgLy/oqrLpoYwx44Gn5aSJ5pu0CgogICAgaW50IHhQYW5lbFNpemU7CiAgICBpbnQgeVBhbmVsU2l6ZTsKICAgIGludCB4LCB5OwogICAgRGltZW5zaW9uIHNpemU7CgogICAgLy/jgrPjg7Pjgrnjg4jjg6njgq/jgr8KICAgIE15TW91c2VTYW1wbGUwMihpbnQgeFBhbmVsU2l6ZSwgaW50IHlQYW5lbFNpemUpIHsgIC8v6Kqy6aGMMeOBp+WkieabtAogICAgICAgIHRoaXMueFBhbmVsU2l6ZSA9IHhQYW5lbFNpemU7CiAgICAgICAgdGhpcy55UGFuZWxTaXplID0geVBhbmVsU2l6ZTsKCiAgICAgICAgYWRkTW91c2VNb3Rpb25MaXN0ZW5lcihuZXcgTXlNb3VzZU1vdGlvbkxpc3RlbmVyKCkpOwogICAgICAgIGFkZE1vdXNlTGlzdGVuZXIobmV3IE15TW91c2VBY3Rpb25MaXN0ZW5lcigpKTsgIC8v6Kqy6aGMMeOBp+i/veWKoAogICAgfQoKICAgIGNsYXNzIE15TW91c2VNb3Rpb25MaXN0ZW5lciBleHRlbmRzIE1vdXNlTW90aW9uQWRhcHRlciB7CgogICAgICAgIHB1YmxpYyB2b2lkIG1vdXNlTW92ZWQoTW91c2VFdmVudCBldnQpIHsKICAgICAgICAgICAgeCA9IGV2dC5nZXRYKCk7CiAgICAgICAgICAgIHkgPSBldnQuZ2V0WSgpOwogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIiggIiArIHggKyAiICwgIiArIHkgKyAiICkiKTsKCiAgICAgICAgICAgIHJlcGFpbnQoKTsKICAgICAgICB9CiAgICB9CgogICAgLy/oqrLpoYwx44Gn6L+95YqgCiAgICBjbGFzcyBNeU1vdXNlQWN0aW9uTGlzdGVuZXIgZXh0ZW5kcyBNb3VzZUFkYXB0ZXIgewoKICAgICAgICBwcml2YXRlIGludCBjbGlja051bWJlciA9IDA7CgogICAgICAgIHB1YmxpYyB2b2lkIG1vdXNlQ2xpY2tlZChNb3VzZUV2ZW50IGV2dCkgewogICAgICAgICAgICBjbGlja051bWJlcisrOwogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIiggIiArIGV2dC5nZXRYKCkgKyAiICwgIiArIGV2dC5nZXRZKCkgKyAiICkgIiArIGNsaWNrTnVtYmVyICsgIuWbnuebruOBruOCr+ODquODg+OCryIpOwogICAgICAgIH0KICAg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