📄 041-045.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, Macmillan Computer Publishing
<br>
<b>ISBN:</b> 1571690433<b> Pub Date:</b> 11/01/96</font>
</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=041-045//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="037-041.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch02/045-052.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading51"></A><FONT COLOR="#000077">The Applet Life Cycle</FONT></H4>
<P>What happens when Joe from Denmark accesses the HTML file Mondrian.html with his Web browser? First, the bytecode contained in Mondrian.class is loaded by the Java runtime environment in Joe’s browser. Then, after ensuring that the bytecode won’t harm Joe’s computer, the methods in Mondrian.java are invoked in the following order:
</P>
<DL>
<DD><B>1.</B> init(). This method is called to initialize the applet.
<DD><B>2.</B> start(). This method starts the execution of the applet.
<DD><B>3.</B> paint(Graphics g). paint() controls what the applet looks like. The browser automatically passes in the Graphics context.
<DD><B>4.</B> stop(). This method is called when the Web page that the applet is running on is hidden, as when Joe clicks on another site. It stops execution of the applet.
<DD><B>5.</B> destroy(). This method releases the resources held by the applet.
</DL>
<P>Figure 1-17 illustrates the short, happy life of an applet that occurs when Joe enters the Mondrian HTML page.
</P>
<P><A NAME="Fig17"></A><A HREF="javascript:displayWindow('images/01-17.jpg',316,584 )"><IMG SRC="images/01-17t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/01-17.jpg',316,584)"><FONT COLOR="#000077"><B>Figure 1-17</B></FONT></A> The Applet life cycle</P>
<P>Congratulations! You’re now a Java artist!
</P>
<H3><A NAME="Heading52"></A><FONT COLOR="#000077">Suggestion Box</FONT></H3>
<DL>
<DD><B>•</B> Pick an object from your surroundings and describe its states, behaviors, and how it interfaces with the world.
<DD><B>•</B> You can use the Mondrian applet to incorporate different colors and shapes. It’s a template for future graphics applets. Look at Appendix A, Java Reference Tables, for the full panoply of graphics methods.
<DD><B>•</B> You can also use standard C/C++ control structures to create more complex patterns. For example, you could use a for loop to draw overlapping rings across the graphics context. You can alternate colors in a loop as well.
<DD><B>•</B> The best way to understand how Java graphics applets work is to experiment. Don’t hesitate to have fun. Who knows, you might even create a great work of art. The journey of a thousand miles begins with one step, as they say.
</DL>
<H3><A NAME="Heading53"></A><FONT COLOR="#000077">Summary</FONT></H3>
<P>This chapter has covered a lot of ground: Java basics, object-oriented fundamentals, some simple Java programs, and a graphics applet. In many ways, you are already over the hump of learning Java. Now you can begin learning the art of writing Java games.
</P>
<P>In the next chapter, you’ll create simple animations with your applets!</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="037-041.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch02/045-052.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</BODY>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -