Java Tank Wars game development

Source: Internet
Author: User

  This article describes:

This article is divided into several parts, intermittent updates. It mainly involves object-oriented thinking, Java GUI drawing, multi-threading, IO, database-related knowledge.

Note: This article is the integration of Hanshunping Teacher's Java Project (code part and Hanshunping teacher has different) and then add some of their own thinking written, this article said some of the tired, but there are hints, if the foundation can be directly skipped , Part of the orientation is only to learn the syntax and object-oriented javase, and part of it is oriented to the knowledge of GUI, multi-threading, IO and database.

I think the project can be a good way to deepen the understanding of object-oriented thinking, and strengthen the basic knowledge of Java consolidation.

  Basic requirements:

    To watch and practice this article, the basic requirement is to learn at least one object-oriented language , to understand some of the basics of object-oriented (keywords and some basic concepts) , and, if you are watching and typing the code, must every word, know why to do so, Why not do that, what is the meaning of doing so, what are the benefits ... Wait a minute. Rather than saying that this can be achieved, and why it is not understood at all, then I think it will be very hard to finish a project, but perhaps nothing!

  Project Body:

    Object oriented thinking, I do not intend to speak this part of the content, so my first part of the body and code should be about GUI drawing technology!

  GUI Drawing Technology (you can skip to the next section or review it already):

The first step to making a tank game is to make a window! There are many ways to make windows in Java, and here we choose JFrame.

The first step: how to make a window (the simplest production window)

1 /**2 * Purpose: Learn how to create a window3  * @authorHP4  *5  */6  Public classTest01extendsjframe{7     //Main function8      Public Static voidMain (string[] args) {9         NewTest01 ();Ten     } One      A     //constructor Method Initialization -      PublicTest01 () { -          This. SetSize (400,300); the          This. setvisible (true); -     } -}

    Code Explanation:

Here, we take the method of inheriting the JFrame class to create the window, Test01 inherits the JFrame class, that is, the subclass of a window class. We define a concept for it that is, it should also be a window class OH. Although the name and window class doesn't seem to matter. But in fact it inherits all the methods and properties of JFrame.

Question 1: Why not create a Window object directly in the main function of this class and create a window, instead of a "dumb method" created after inheriting it?

Since we cannot modify the code in the JFrame class, we can no longer add our various features to the window class to satisfy our requirements for the window class, so we use a class of my window MyFrame (here is Test01) to satisfy our own needs!

Question 2: Why not use a function that creates a window to load the code in the constructor now, making the code more meaningful?

Because this is our own window (MyFrame), that is, I do not need to use this time (custom window), and, when we create our own window, we need to create an object to directly appear in the window. Because our own needs are clear, and this class does not serve others.

=============================================================================================================== =============================================================

Not to be continued!

=============================================================================================================== =============================================================

    

Java Tank Wars game development

Related Article

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.