⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 001-010.html

📁 java game programming e-book
💻 HTML
字号:
<HTML>
<HEAD>
<META name=vsisbn content="1571690433"><META name=vstitle content="Black Art of Java Game Programming"><META name=vsauthor content="Joel Fan"><META name=vsimprint content="Sams"><META name=vspublisher content="Macmillan Computer Publishing"><META name=vspubdate content="11/01/96"><META name=vscategory content="Web and Software Development: Programming, Scripting, and Markup Languages: Java"><TITLE>Black Art of Java Game Programming:Fundamental Java</TITLE>
<!-- HEADER --><STYLE type="text/css">  <!-- A:hover  { 	color : Red; } --></STYLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><script><!--function displayWindow(url, width, height) {         var Win = window.open(url,"displayWindow",'width=' + width +',height=' + height + ',resizable=1,scrollbars=yes');	if (Win) {		Win.focus();	}}//--></script><SCRIPT><!--function popUp(url) {        var Win = window.open(url,"displayWindow",'width=400,height=300,resizable=1,scrollbars=yes');	if (Win) {		Win.focus();	}}//--></SCRIPT><script language="JavaScript1.2"><!--function checkForQuery(fm) {  /* get the query value */  var i = escape(fm.query.value);  if (i == "") {      alert('Please enter a search word or phrase');      return false;  }                  /* query is blank, dont run the .jsp file */  else return true;  /* execute the .jsp file */}//--></script></HEAD><BODY> 
<TABLE border=0 cellspacing=0 cellpadding=0>
<tr>
<td width=75 valign=top>
<img src="../1571690433.gif" width=60 height=73 alt="Black Art of Java Game Programming" border="1">
</td>
<td align="left">
    <font face="arial, helvetica" size="-1" color="#336633"><b>Black Art of Java Game Programming</b></font>
    <br>
    <font face="arial, helvetica" size="-1"><i>by Joel Fan</i>
    <br>
    Sams,&nbsp;Macmillan Computer Publishing
    <br>
    <b>ISBN:</b>&nbsp;1571690433<b>&nbsp;&nbsp;&nbsp;Pub Date:</b>&nbsp;11/01/96</font>&nbsp;&nbsp;
</td>
</tr>
</table>
<P>

<!--ISBN=1571690433//-->
<!--TITLE=Black Art of Java Game Programming//-->
<!--AUTHOR=Joel Fan//-->
<!--AUTHOR=Eric Ries//-->
<!--AUTHOR=Calin Tenitchi//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Sams//-->
<!--CHAPTER=1//-->
<!--PAGES=001-010//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ewtoc.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="010-014.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H2 ALIGN="CENTER"><FONT COLOR="#000077"><I>Part I<BR>Fundamentals of Java Game Development
</I></FONT></H2>
<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 1<BR>Fundamental Java
</FONT></H2>
<P><I>Joel Fan</I></P>
<P><FONT SIZE="+1"><B>Goals:</B></FONT></P>
<P>Understand the fundamentals of Java
</P>
<P>Understand basics of object-oriented design</P>
<P>Create simple Java graphics applets</P>
<P>You&#146;ve heard about Java, and you&#146;ve seen what it does for the World Wide Web. Imagine what <I>you</I> can do with it. In this chapter, you&#146;ll get a quick jump on learning Java and creating graphics with Java. You&#146;ll also learn about object-oriented programming, which is necessary for unleashing the full power of Java. By the end of this chapter, you&#146;ll know how to use Java to create a graphics applet that will spice up any Web page. So hold on to your mouse for an exciting ride!</P>
<P>But first, <I>what exactly is Java?</I></P>
<H3><A NAME="Heading2"></A><FONT COLOR="#000077">What Is Java?</FONT></H3>
<P>Java is a programming language that&#146;s engineered for the demands of the Internet. Although Java is a relatively new language (the 1.0 release appeared early in 1996), it has received intense media coverage and even engendered speculation about seismic shifts in the software industry! Let&#146;s see why Java has created such excitement, and why it&#146;s an innovative platform for creating games. First of all, you should understand how Java dramatically changes the nature of the World Wide Web.
</P>
<H4 ALIGN="LEFT"><A NAME="Heading3"></A><FONT COLOR="#000077">The World Wide Web</FONT></H4>
<P>The World Wide Web, simply put, is a collection of hyperlinked documents that reside on computers throughout the world. Figure 1-1 shows a diagram of the Web.
</P>
<P><A NAME="Fig1"></A><A HREF="javascript:displayWindow('images/01-01.jpg',559,379 )"><IMG SRC="images/01-01t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/01-01.jpg',559,379)"><FONT COLOR="#000077"><B>Figure 1-1</B></FONT></A>&nbsp;&nbsp;The World Wide Web</P>
<P>The Web achieves its wide reach by allowing computers connected to the Internet to request and transmit documents using the Web protocol. This protocol, called HTTP (HyperText Transfer Protocol), is based on the <I>client-server</I> paradigm: a <I>client</I> requests a service, and a <I>server</I> fulfills this request. Thus, a Web client requests a document from a Web server, and the server returns the desired document. The interaction that occurs between a Web client and server is illustrated in Figure 1-2.</P>
<P><A NAME="Fig2"></A><A HREF="javascript:displayWindow('images/01-02.jpg',558,381 )"><IMG SRC="images/01-02t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/01-02.jpg',558,381)"><FONT COLOR="#000077"><B>Figure 1-2</B></FONT></A>&nbsp;&nbsp;Interaction between a Web client and server</P>
<P>The most common type of Web client is a <I>browser</I>, such as Netscape&#146;s Navigator or Microsoft&#146;s Internet Explorer. Browsers allow you to request documents by pointing and clicking, and they display Web documents in an attractive format.</P>
<P>The appearance of the document on your screen is suggested by the HTML (HyperText Markup Language) tags embedded in the document. HTML controls such things as the formatting of text or the alignment of an image, but it doesn&#146;t provide facilities for creating dynamic multimedia, such as animations or video games. In other words, once an HTML document is loaded and displayed, it doesn&#146;t do anything (unless it contains an animated GIF). As a result, the HTML documents found on most Web pages are static and unchanging. For example, Figure 1-3 shows an HTML document as displayed by a Web browser. The actual Web page is as passive as the figure in this book.</P>
<P><A NAME="Fig3"></A><A HREF="javascript:displayWindow('images/01-03.jpg',502,453 )"><IMG SRC="images/01-03t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/01-03.jpg',502,453)"><FONT COLOR="#000077"><B>Figure 1-3</B></FONT></A>&nbsp;&nbsp;Web page and HTML document</P>
<P>Now let&#146;s see how a Java applet can liven up an HTML document.
</P>
<H4 ALIGN="LEFT"><A NAME="Heading4"></A><FONT COLOR="#000077">What Is a Java Applet?</FONT></H4>
<P>A Java <I>applet</I> is a program that a browser can download and execute. To add an applet to a Web document, you insert an HTML tag that tells the browser where to find the applet. The browser loads the HTML document and the applet. When the applet finishes loading, it runs on the client computer. Figure 1-4 illustrates the interaction between the Web server, browser, and applet.</P>
<P><A NAME="Fig4"></A><A HREF="javascript:displayWindow('images/01-04.jpg',560,380 )"><IMG SRC="images/01-04t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/01-04.jpg',560,380)"><FONT COLOR="#000077"><B>Figure 1-4</B></FONT></A>&nbsp;&nbsp;Interaction between Web server, browser, and applet</P>
<P>Since Java is a full-fledged programming language, applets can do things that aren&#146;t possible with HTML. For example, you can create animations and other dynamic multimedia presentations with Java applets, such as games. Applets can open a network connection back to the server they were downloaded from, which enables you to implement chat rooms and multiplayer games. Since applets run on the local computer, interactive performance is relatively quick and stable. Thus, you can create a video game applet and include it on a Web page.
</P>
<P>Now that you know what Java can do, let&#146;s see why you should write games with it.</P>
<H4 ALIGN="LEFT"><A NAME="Heading5"></A><FONT COLOR="#000077">Advantages to Writing Games in Java</FONT></H4>
<P>Here are five reasons that make Java a great environment for writing games:
</P>
<DL>
<DD><B>&#149;</B>&nbsp;&nbsp;<I>It allows you to distribute your games on the Web.</I> The Web is a revolutionary medium for the distribution of information, such as news, music, intergalactic pictures, and&#151;software! With Java, you can create games that anybody with a Web browser can access. This means an instant worldwide audience, and it&#146;s a vast improvement over writing games that only your kids have access to.
<DD><B>&#149;</B>&nbsp;&nbsp;<I>It supports multiple platforms</I>. In many programming environments, programs are compiled and linked to create executable code that is specific to a particular platform. In contrast, a Java program compiles to <I>bytecode</I>, which is executed by the Java virtual machine (JVM). The JVM isn&#146;t a real computer, but an abstract machine that can be simulated on many computers, regardless of CPU or OS. Thus, any platform that implements the JVM will be able to run your bytecode. In addition, by using Java&#146;s Abstract Windowing Toolkit (AWT), your game can have the appropriate look and feel regardless of the underlying window system. In concrete terms, this means you can compile a Java game once, and it will run on any computer that has a Java-enabled browser, such as the Netscape Navigator. The combination of multiplatform support and worldwide distribution over the Web gives Java games the widest possible audience.
<DD><B>&#149;</B>&nbsp;&nbsp;<I>It facilitates interaction by multiple players</I>. The more the merrier, as the saying goes, and with Java, you can easily allow multiple players from around the Web to compete against one another. Java has libraries that support Web and Internet protocols, so applets running on different computers can communicate with each other. Now, instead of playing against your PC, you can challenge Joe from Denmark.
<DD><B>&#149;</B>&nbsp;&nbsp;<I>It is an object-oriented programming language</I>. Being object-oriented makes Java a great language to write games in, since it helps you manage complexity and reuse your code, thereby cutting down on development time. The object metaphor is ideal for creating graphics and games. Although diehard C programmers may scoff at the additional overhead used by object-oriented programs at runtime, some benchmarks show that an object-oriented program may even run faster than a comparable program written in a procedural style! (Of course, it depends on who&#146;s writing the program...)
<DD><B>&#149;</B>&nbsp;&nbsp;<I>It is simple</I>. Java is a simple language in several ways. First, Java&#146;s syntax resembles that of C and C&#43;&#43;, so it is simple to learn for C and C&#43;&#43; programmers. Second, Java eliminates features from C and C&#43;&#43; that the designers of Java felt were redundant or led to poorly written or insecure code. The result is a smaller, simpler language than either C or C&#43;&#43;. Third, Java makes memory management simple, with the elimination of pointers and the use of garbage collection to reclaim unused allocated memory. This removes a common source of bugs and frustration. The simplicity of Java makes games easier to understand and debug, which simplifies your task as a programmer.
</DL>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ewtoc.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="010-014.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>


</BODY>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -