/** * Author: @author Zhangshaowen * Date: 2013-12-04 * Function: Tank 1.0 * * Package com.tank;
Import javax.swing.*;
Import java.awt.*;
public class MyTankGame1 extends jframe{Mypanel MP = null;
public static void Main (string[] args) {//TODO auto-generated method Stub new MyTankGame1 ();
}//Constructor public MyTankGame1 () {MP = new Mypanel ();
This.add (MP);
This.setsize (400,300);
This.setdefaultcloseoperation (Jframe.exit_on_close);
This.setvisible (TRUE);
}//My panel class Mypanel extends jpanel{//define a tank Hero Hero = null;
Constructor public Mypanel () {hero = new Hero (10,10);
}//re-paint public void paint (Graphics g) {super.paint (g);
G.fillrect (0, 0, 400, 300);
This.drawtank (Hero.getx (), Hero.gety (), g, 0, 1);
/** *//Draw tank function * @param x start position x * @param y start position y * @param g brush * @param direct Tank Direction * @param type of tank */public void Drawtank (int x,int y,graphics g,int direct,int type) {switch (type) {//Judge tank type (my tank, or enemy) case0:g.setcolor (Color.cyan);
Break
Case 1:g.setcolor (Color.yellow);
Switch (direct) {//judge the direction of the tank case 0://Draw out my tank//1. Draw the left rectangle G.fill3drect (x, Y, 5, false);
2. Draw the right rectangle G.fill3drect (x+15, Y, 5, false);
3. Draw the middle rectangular g.fill3drect (x+5, Y+5, A, false);
4. Draw Round G.filloval (x+4, y+10, 10, 10);
5. Draw Outlet G.drawline (x+10, y, x+10, y+5);
Break
}}//Tank class tank{//x represents the horizontal axis of the tank int x=0;
Y indicates the ordinate int y=0 of the tank;
Constructor 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;
The public void sety (int y) {this.y = y;
}//My tank class Hero extends tank{//constructor public Hero (int x,int y) {//Call the constructor of the parent class super (x, y);
}
}