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

📄 041-045.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=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&#146;s browser. Then, after ensuring that the bytecode won&#146;t harm Joe&#146;s computer, the methods in Mondrian.java are invoked in the following order:
</P>
<DL>
<DD><B>1.</B>&nbsp;&nbsp;init(). This method is called to initialize the applet.
<DD><B>2.</B>&nbsp;&nbsp;start(). This method starts the execution of the applet.
<DD><B>3.</B>&nbsp;&nbsp;paint(Graphics g). paint() controls what the applet looks like. The browser automatically passes in the Graphics context.
<DD><B>4.</B>&nbsp;&nbsp;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>&nbsp;&nbsp;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>&nbsp;&nbsp;The Applet life cycle</P>
<P>Congratulations! You&#146;re now a Java artist!
</P>
<H3><A NAME="Heading52"></A><FONT COLOR="#000077">Suggestion Box</FONT></H3>
<DL>
<DD><B>&#149;</B>&nbsp;&nbsp;Pick an object from your surroundings and describe its states, behaviors, and how it interfaces with the world.
<DD><B>&#149;</B>&nbsp;&nbsp;You can use the Mondrian applet to incorporate different colors and shapes. It&#146;s a template for future graphics applets. Look at Appendix A, Java Reference Tables, for the full panoply of graphics methods.
<DD><B>&#149;</B>&nbsp;&nbsp;You can also use standard C/C&#43;&#43; 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>&#149;</B>&nbsp;&nbsp;The best way to understand how Java graphics applets work is to experiment. Don&#146;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&#146;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 + -