|
@@ -16,6 +16,7 @@ public class BallMove extends JFrame{
|
16
|
16
|
MyPanel myPanel = new MyPanel();
|
17
|
17
|
this.add(myPanel);
|
18
|
18
|
this.setSize(400,300);
|
|
19
|
+ this.addKeyListener(myPanel);
|
19
|
20
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
20
|
21
|
this.setVisible(true);
|
21
|
22
|
}
|
|
@@ -28,7 +29,9 @@ class MyPanel extends JPanel implements KeyListener {
|
28
|
29
|
|
29
|
30
|
@Override
|
30
|
31
|
public void keyPressed(KeyEvent e) {
|
31
|
|
-
|
|
32
|
+ if(e.getKeyCode() == KeyEvent.VK_DOWN) {
|
|
33
|
+ System.out.println("按下了向下的按键");
|
|
34
|
+ }
|
32
|
35
|
}
|
33
|
36
|
|
34
|
37
|
@Override
|