Tank Wars-first day (draw tank)

Source: Internet
Author: User
Tags gety
/** * 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);
		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);
	}}//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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.