質問するログイン新規登録

回答編集履歴

2

var

2021/01/04 08:48

投稿

TN8001
TN8001

スコア10180

answer CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  public class Mouse extends JPanel { // JPanelベースに
14
14
  public static void main(String[] args) {
15
- JFrame frame = new JFrame();
15
+ var frame = new JFrame();
16
16
  frame.setSize(500, 500);
17
17
  frame.setLocationRelativeTo(null);
18
18
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -32,8 +32,8 @@
32
32
  public Mouse() {
33
33
  addMouseListener(new MouseAdapter() { // 不要なメソッドが邪魔なのでアダプタで
34
34
  @Override public void mousePressed(MouseEvent e) { // ClickedからPressedに変更
35
- int clickX = e.getPoint().x;
35
+ var clickX = e.getPoint().x;
36
- int clickY = e.getPoint().y;
36
+ var clickY = e.getPoint().y;
37
37
 
38
38
  if (x1 < clickX && clickX < x1 + 50 && y1 < clickY && clickY < y1 + 50) {
39
39
  command = 1;
@@ -97,7 +97,7 @@
97
97
 
98
98
  public class Mouse extends JPanel {
99
99
  public static void main(String[] args) {
100
- JFrame frame = new JFrame();
100
+ var frame = new JFrame();
101
101
  frame.setSize(500, 500);
102
102
  frame.setLocationRelativeTo(null);
103
103
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

1

描画

2021/01/04 08:48

投稿

TN8001
TN8001

スコア10180

answer CHANGED
@@ -83,7 +83,7 @@
83
83
 
84
84
  ---
85
85
 
86
- 画像を`JLabel`で表示すれば、当たり判定や描画等を`Swing`に任せられてかなり手を抜けます。
86
+ 画像を`JLabel`で表示すれば、当たり判定や描画等を`Swing`に任せられてかなり手を抜けます。
87
87
  ```Java
88
88
  import java.awt.Point;
89
89
  import java.awt.event.MouseAdapter;