A preliminary study of Java game programming

Source: Internet
Author: User

Now the popular game seems to be developed in C or C + +. There are few popular games on the Java platform that are very large and can be played. Since Java is a new language, many of his features have yet to be explored, but we cannot deny the power of Java in game programming. This article will lead you step-by-step learning to write Java games. And eventually build your own Java game.

Before we start, we have to make sure that you have the Java JDK installed and that you have installed the browser software such as IE. This chapter is an Internet-development object, step-by-step to teach you to understand the Java thread, Applets ... and game programming to pay attention to some aspects and in each small part of the corresponding source code for your reference, and finally we will be the game program to guide the prompts. In the article we also interspersed a lot of constructive questions, let the reader participate in our development. But since this chapter refers to leading people into this threshold, most of the knowledge is not very detailed, interested readers can access the relevant information supplements. Before we begin we have to make sure that you already know the class, inheritance, and some basic attributes of the Java language.

Basic applets

Applets is a web browser applet, because the applet is absolutely safe for the system, so it does more than Aaplication limited, but for the client's program, applets is still a very powerful tool. In order to browse and run conveniently, we use applet as the development object.

To develop the applets program, we have to inherit the applet class and overwrite the necessary functions, and the following functions control the generation and execution of applets on the Web page.

Function Role
Init () This function is automatically invoked to perform the initialization action of the applet-including the allocation of the component on the layout-you must overwrite it
Start () Each time the browser displays the applet content, it is invoked to allow the applet to open its regular work (especially those that are closed by stop), which is called after the call to Init ()
Stop () It is invoked whenever the browser does not display the content. Let the applet close some resource-consuming work, and call Destory () after calling the function
Destroy () When the browser removes the applet from the Web page, it is invoked to perform actions such as the last released resource that the applet is no longer using
Paint () Allows you to do the corresponding painting on the applet interface, each refresh will be repaint

All applet file source file names are the same as Java applications. Java is the extension, the compiled executable file name extension is. class, because there is no main () function in the applet, it is automatic integration with HTML, so we want to execute the applet, To put a specific tag (tag) in an HTML source file to tell the Web page how to load and execute the applet, it is important to note that the Web page we are executing must be able to execute Java programs.

Common HTML Source code format

<HTML>
<APPLET CODE="HelloWorld.class" WIDTH=300 HEIGHT=500>
</APPLET>
</HTML

<applet code = "Helloworld.class" width=300 height=500> this line is the applet's execution office.

Applet executes document as = "Helloworld.class" tells Web page "applet" extension file as Helloworld.class

Width and height tell the browser the size of this display applet

For a description of tags (tag), you can find a lot of relevant documentation on the Internet.

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.