/*
-
画 出坦克
/
package gui;
import javax.swing.;
import java.awt.*;
public class MyTankGame01 extends JFrame {MyPanel mp = null;
public static void main(String[] args) {
// TODO Auto-generated method stubMyTankGame01 mtg = new MyTankGame01 () ;
}
//构造函数
public MyTankGame01(){
mp = new MyPanel();
this.add(mp);
//this.setContentPane(mp);
this.setSize(400, 300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
// 我的面板
class MyPanel extends JPanel {
//定义我的坦克
Hero hero= null ;
public void MyPanel(){
hero = new Hero (10,10);
}
// 重新paint
public void paint (Graphics g){
super.paint(g);
g.fillRect(0,0,400,300);
g.setColor(Color.yellow);
//画出我的坦克(到时候封装成一个函数)
// 1 :画出左面的举行
g.draw3DRect(hero.getX(),hero.getY(),5,30,false);
}
}
//坦克类
class Tank {
// 位置x 表示坦克的横坐标 纵坐标
int x = 0 ;
int y = 0;
public Tank (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 Tank{
public Hero (int x, int y ){
super(x,y );
}
}