import java.awt.*;
import javax.swing.*;
public class TankTest extends JFrame {
Mypanel mp=null;
public static void main(String[] args) {
TankTest tank=new TankTest();
}
public TankTest() {
this.setSize(400, 300);
this.setVisible(true);
this.setTitle("坦克");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mp=new Mypanel();
this.add(mp);
}
}
class Mypanel extends JPanel{
Hero hero=null;
public Mypanel() {
hero=new Hero(10, 10);
}
public void print(Graphics g) {
super.paint(g);
g.fillRect(0, 0, 400,300);
this.drawtank(hero.getX(), hero.getY(), g, 0, 0);
}
public void drawtank(int x,int y,Graphics g,int direction,int type) {
switch(type) {
case 0:
g.setColor(Color.blue);
break;
case 1:
g.setColor(Color.green);
break;
}
switch(direction) {
case 0:
g.fillRect(x, y, 5, 30);
g.fillRect(x+15,y, 5, 30);
g.fillRect(x+5, y+5, 10, 20);
g.fillOval(x+5, y+15, 10, 10);
g.drawLine(x+10, y+15, x+10, y+15);
break;
case 1:
}
}}
class Tanks{
int x=50;
int y=50;
public Tanks(int x,int y) {
this.x=x;
this.y=y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}}
class Hero extends Tanks{
public Hero(int x,int y) {
super(x,y);
}}