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

📄 338-340.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:Advanced Networking and Multiplayer Gaming Concepts</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=9//-->
<!--PAGES=338-340//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="335-338.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="340-344.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
</P>
<H4 ALIGN="LEFT"><A NAME="Heading41"></A><FONT COLOR="#000077">Component Commands and Methods</FONT></H4>
<P>All Components are subclassed from java.awt.Component. This gives them each a certain amount of common behavior, but each type also has its own commands and methods that you have to learn. First, let&#146;s review some of the more important methods that we will use.
</P>
<H4 ALIGN="CENTER"><A NAME="Heading42"></A><FONT COLOR="#000077">Common Component Methods</FONT></H4>
<DL>
<DD><B>&#149;</B>&nbsp;&nbsp;enable(), disable(). These enable or disable a Component. Different Components handle being disabled differently.
<DD><B>&#149;</B>&nbsp;&nbsp;getFont(), setFont(). These control the Font being used by a Component. Obviously, this has no effect on Components that do not use text.
<DD><B>&#149;</B>&nbsp;&nbsp;getForeground(), getBackground(), setForeground(), setBackground(). These allow you to control the foreground and background colors of a Component. Use them to spice up your Components whenever you feel the need.
<DD><B>&#149;</B>&nbsp;&nbsp;handleEvent(Event). These are called when an Event must be handled. Each Component should also pass along any unhandled events to its parent using this method.
<DD><B>&#149;</B>&nbsp;&nbsp;layout(). This method causes the Component to restructure and redraw itself. This is a good way to force a Component and all embedded Components to be redrawn.
</DL>
<P>This list is by no means comprehensive. As you work more with Components, you will have to explore the java.awt.Component class more and more. Some of the Components we will be using in this applet also have their own methods that you should be familiar with. The most important to review at this time are the methods used in the List Component. Here are some of them:
</P>
<H4 ALIGN="CENTER"><A NAME="Heading43"></A><FONT COLOR="#000077">Methods Unique to List</FONT></H4>
<DL>
<DD><B>&#149;</B>&nbsp;&nbsp;List.addItem(String).This adds a String item to the List.
<DD><B>&#149;</B>&nbsp;&nbsp;List.clear().This clears all items off of the List. Unfortunately, as of this writing, this method is broken in the Java language itself&#150;<I>it does not work properly and should be avoided at all costs until it is fixed.</I> Hopefully, Sun will have fixed the List class by the time you read this.
<DD><B>&#149;</B>&nbsp;&nbsp;List.select(int), deselect(int). These cause an item to be selected/deselected. Items are kept in the List in an array, so that the first item is always at index 0.
</DL>
<P>List.getRows(), getItems(). These get the number of rows/items (usually, but not always, the same) in a List.
</P>
<H4 ALIGN="LEFT"><A NAME="Heading44"></A><FONT COLOR="#000077">Planning Your Event-Handling Strategy</FONT></H4>
<P>A good thing to do before you start writing code is to think about what events you are going to have to handle. Before we can do that, we have to know how exactly an event works. Whenever a Component generates an event, it is sent up the hierarchy until it is either handled or it runs out of Components. For instance, when one of our Buttons is pushed, it generates an Event. This Event is first sent to the Button, then to the Panel in which the Button sits, and then to the Panel in which the first Panel is embedded (which, in this case, would be our Applet). Each Event has certain properties you should be aware of.
</P>
<H4 ALIGN="CENTER"><A NAME="Heading45"></A><FONT COLOR="#000077">Basic Events and Their Properties</FONT></H4>
<P>Here is a summary of some of the basic ones we will need (assume we are dealing with an Event object named <I>evt</I>):</P>
<DL>
<DD><B>&#149;</B>&nbsp;&nbsp;<I>evt.id</I> is a number that signifies what the Event means. You don&#146;t have to memorize <I>id</I> numbers, luckily, because the Event class provides a nice long list of constants that you can use. For instance, whenever an item in a List is selected, a LIST_SELECT Event is generated (<I>evt.id == Event.LIST_SELECT</I>). The table below lists all of the Event.id constants.
<DD><B>&#149;</B>&nbsp;&nbsp;<I>evt.target</I> is the Object that generated the Event. This is most useful along with the <I>instanceof</I> operator, which is used to determine if a given Object is a subclass of a particular class. For instance, if <I>evt</I> is a LIST_SELECT Event, then (<I>evt instanceof List</I>) will evaluate to <I>true</I>.
<DD><B>&#149;</B>&nbsp;&nbsp;<I>evt.arg</I> is the argument passed along with the Event. What exactly this is varies from component to component, but Buttons pass a String representing their labels. This is useful for determining which Button has been pressed by the user.
</DL>
<P>These are the major properties of the Event class that we will use. You will need this information to write this applet&#146;s handleEvent() method, but we will get to that later. Just be sure you understand the function and operation of Events before continuing. (Sun&#146;s tutorial has especially good examples of how this works.) See Table 9-1 for a list of Event.id constants. (For a more extensive discussion of events and event handling in Java, see Chapter 4, Adding Interactivity.)
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="335-338.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="340-344.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>


</BODY>

⌨️ 快捷键说明

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