|
|
@ -1,6 +1,8 @@
|
|
|
|
package com.msb;
|
|
|
|
package com.msb;
|
|
|
|
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
|
|
import java.awt.event.KeyAdapter;
|
|
|
|
|
|
|
|
import java.awt.event.KeyEvent;
|
|
|
|
import java.awt.event.WindowAdapter;
|
|
|
|
import java.awt.event.WindowAdapter;
|
|
|
|
import java.awt.event.WindowEvent;
|
|
|
|
import java.awt.event.WindowEvent;
|
|
|
|
|
|
|
|
|
|
|
@ -16,10 +18,12 @@ public class TankFrame extends Frame {
|
|
|
|
private int y = 200;
|
|
|
|
private int y = 200;
|
|
|
|
|
|
|
|
|
|
|
|
public TankFrame() {
|
|
|
|
public TankFrame() {
|
|
|
|
|
|
|
|
|
|
|
|
setTitle("Tank war");
|
|
|
|
setTitle("Tank war");
|
|
|
|
setSize(800, 600);
|
|
|
|
setSize(800, 600);
|
|
|
|
setResizable(true);
|
|
|
|
setResizable(true);
|
|
|
|
setVisible(true);
|
|
|
|
setVisible(true);
|
|
|
|
|
|
|
|
|
|
|
|
addWindowListener(new WindowAdapter() {
|
|
|
|
addWindowListener(new WindowAdapter() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void windowClosing(WindowEvent e) {
|
|
|
|
public void windowClosing(WindowEvent e) {
|
|
|
@ -27,11 +31,31 @@ public class TankFrame extends Frame {
|
|
|
|
System.exit(0);
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addKeyListener(new MyKeyListener());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
super.paint(g);
|
|
|
|
super.paint(g);
|
|
|
|
g.fillRect(x, y, 50, 50);
|
|
|
|
g.fillRect(x, y, 50, 50);
|
|
|
|
|
|
|
|
x += 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//这里使用内部内的原因是,只有TankFrame用到
|
|
|
|
|
|
|
|
class MyKeyListener extends KeyAdapter {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void keyPressed(KeyEvent e) {
|
|
|
|
|
|
|
|
super.keyPressed(e);
|
|
|
|
|
|
|
|
/*x += 10;
|
|
|
|
|
|
|
|
repaint();*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void keyReleased(KeyEvent e) {
|
|
|
|
|
|
|
|
super.keyReleased(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|