亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch9.htm

?? 有關于游戲開發的教程我閱讀后感覺不錯所以就拿出來與大家共享。
?? HTM
?? 第 1 頁 / 共 2 頁
字號:
<HTML>

<HEAD>
   <TITLE>Chapter 9 -- Handling User Input with Java</TITLE>
   <META>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910">
<H1><FONT COLOR=#FF0000>Chapter 9</FONT></H1>
<H1><B><FONT SIZE=5 COLOR=#FF0000>Handling User Input with Java</FONT></B>
</H1>
<P>
<HR WIDTH="100%"></P>
<P>
<H3 ALIGN=CENTER><FONT COLOR="#000000"><FONT SIZE=+2>CONTENTS<A NAME="CONTENTS"></A>
</FONT></FONT></H3>

<UL>
<LI><A HREF="#EventDrivenProgramming" >Event-Driven Programming</A>
<LI><A HREF="#JavaInputEvent" >Java Input Event</A>
<LI><A HREF="#awtEventHandling" >awt Event Handling</A>
<LI><A HREF="#KeyboardEvents" >Keyboard Events</A>
<LI><A HREF="#MouseEvents" >Mouse Events</A>
<LI><A HREF="#SampleAppletFlyingSaucer" >Sample Applet: Flying Saucer</A>
<LI><A HREF="#Summary" >Summary </A>
<LI><A HREF="#QA" >Q&amp;A</A>
<LI><A HREF="#Workshop" >Workshop</A>
<UL>
<LI><A HREF="#Quiz" >Quiz</A>
<LI><A HREF="#Exercises" >Exercises</A>
</UL>
</UL>
<HR>
<P>
Now that you have an idea about the role that user input plays
in games, you're ready to learn the specifics of how user input
works in Java. This lesson is devoted to the handling of user
input in Java, including the supported input devices and the methods
used to trap input events. You also learn about the event-driven
structure of Java event handling and how it applies to input events.
<P>
This lesson clearly establishes the fact that Java user input
handling is both powerful and simple. A handful of methods is
really all it takes to deal with user input in a Java game. You
get to see this firsthand by building a Java applet with keyboard
and mouse input support. Let's get started.
<H2><A NAME="EventDrivenProgramming"><B><FONT SIZE=5 COLOR=#FF0000>Event-Driven
Programming</FONT></B></A></H2>
<P>
Before getting into the details of how user input is handled in
Java, it's important that you understand how event-driven programming
works. This is important because user input in Java is heavily
based on the event-driven architecture that makes up the heart
of Java. In Java, an <I>event</I> is defined quite literally as
something that happens that you might want to know about. For
example, when a Java component gains the input focus, an event
occurs because it might be important for your applet to know about
the focus change.
<P>
An <I>event</I> is something that happens that you might want
to know about and possibly react to.
<P>
In the event-driven world of Java, the flow of your program follows
events external to your applet, as opposed to following an internally
linear program flow. This is an important point because it means
that a Java applet is in a constant state of responding to events.
The most visible events are things such as mouse clicks and key
presses, which are known as <I>input events</I>. You provide methods
that respond to these events, which are called <I>event handlers</I>.
<P>
An <I>input event</I> is an event generated by user manipulation
of an input device such as the mouse or keyboard.
<P>
<I>Event handlers</I> are special methods that are used to respond
or react to events.
<P>
Because of the inherent graphical nature of Java applets, it will
eventually become obvious to you why the event-driven programming
model is not only more convenient, but downright necessary. With
the potential of having multiple applets on a single Web page,
along with on-the-fly system configuration changes and a multitude
of other things going on, a procedural programming model would
be much more difficult to manage. The event-based model provides
a more sound solution to the problems inherent in a system with
a graphical interface, such as Java.
<P>
All events in Java are processed within the awt windowing toolkit
package, and they are tightly linked to awt components. A component
is basically a generic abstraction for a Java window. You might
recall that Java applets are themselves a specific type of component,
which means that they inherit the same event-processing features
built into the <TT><FONT FACE="Courier">Component</FONT></TT>
superclass.
<P>
A <I>component</I> is a generic abstraction of a window in Java.
<H2><A NAME="JavaInputEvent"><B><FONT SIZE=5 COLOR=#FF0000>Java
Input Event</FONT></B></A></H2>
<P>
As you just learned, user input in Java is handled through an
event-driven architecture. When the user interacts with an input
device, it results in an input event being dispatched to the component
with the input focus. In most cases, this component is the applet
window. An input event is a special type of event that notifies
an applet that something has occurred on an input device. An example
of an input event is a movement of the mouse.
<P>
Input events are crucial in Java games because they provide a
means of handling user responses. Without being able to monitor
user responses, Java games wouldn't be too exciting. User response
handling is not only important for providing an interface to the
user for playing a game; it also establishes much of the feel
of a game. Simply altering the means by which you provide user
response support can dramatically alter the play of a game. This
is an important point, one that you'll deal with later in this
lesson when you develop the Flying Saucer sample applet.
<P>
Java user event responses come in two varieties, which correspond
to the input devices supported by Java. The two types of input
events supported by release 1.0 of Java are as follows:
<UL>
<LI>Keyboard events
<LI>Mouse events
</UL>
<P>
Keyboard events are events generated by a key press on the keyboard.
Any time the user presses a key, a keyboard event is generated
that can be trapped and handled by the applet with the input focus.
Actually, a key press generates two events: a key down event and
a key up event. You'll learn more about these two types soon.
<P>
Mouse events are generated by mouse clicks and movements. Every
mouse click and mouse movement generates a corresponding mouse
input event. Like key presses, mouse clicks actually come as a
series of events: a mouse click down event and a mouse click up
event. A mouse event is also specifically targeted at mouse dragging.
Mouse dragging occurs when the mouse is moved with the button
down. Applets that want to respond to mouse clicks and movement
simply have to process these events and take action accordingly.
You learn more about processing mouse events a little later in
this lesson.
<P>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><B>Note</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
You might have noticed in the discussion of mouse events the mention of the mouse <I>button</I>, as opposed to the mouse <I>buttons</I>. This is intentional because Java only supports a single mouse button. This might seem limiting to users on some 
platforms, such as Windows, but keep in mind that Java is designed to support as many platforms as possible. Considering the fact that some platforms (such as Macintosh) have mice with a single button, it makes sense for Java to support only a single 
button.
</BLOCKQUOTE>

</TD></TR>
</TABLE></CENTER>
<P>
<H2><A NAME="awtEventHandling"><B><FONT SIZE=5 COLOR=#FF0000>awt
Event Handling</FONT></B></A></H2>
<P>
Before getting into the specific event handlers for keyboard and
mouse events, let's look at how events are handled in a general
sense in Java. The Java awt provides the <TT><FONT FACE="Courier">Event</FONT></TT>
class for encapsulating all types of events that can occur within
the system. The <TT><FONT FACE="Courier">Event</FONT></TT> class
models a generic event and has constants defined within it to
represent specific events. The <TT><FONT FACE="Courier">Event</FONT></TT>
class is used primarily by the <TT><FONT FACE="Courier">handleEvent</FONT></TT>
method of <TT><FONT FACE="Courier">Component</FONT></TT>. The
<TT><FONT FACE="Courier">handleEvent</FONT></TT> method is the
default event handler for all events, and is defined as follows:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public boolean handleEvent(Event evt)</FONT></TT>
</BLOCKQUOTE>
<P>
Notice that <TT><FONT FACE="Courier">handleEvent</FONT></TT> takes
an <TT><FONT FACE="Courier">Event</FONT></TT> object as its only
parameter. <TT><FONT FACE="Courier">handleEvent</FONT></TT> uses
this <TT><FONT FACE="Courier">Event</FONT></TT> object to determine
what type of event has occurred. It then calls a more specific
event handler method to deal with the specific event. For example,
if a key is pressed, the <TT><FONT FACE="Courier">Event</FONT></TT>
object's <TT><FONT FACE="Courier">id</FONT></TT> member variable
is set to <TT><FONT FACE="Courier">KEY_PRESS</FONT></TT>, which
is a constant defining the key press event. <TT><FONT FACE="Courier">handleEvent</FONT></TT>
checks the value of <TT><FONT FACE="Courier">id</FONT></TT> and,
upon finding it equal to <TT><FONT FACE="Courier">KEY_PRESS</FONT></TT>,
calls the <TT><FONT FACE="Courier">keyDown</FONT></TT> handler
method. Listing 9.1 shows the key press handling portion of the
<TT><FONT FACE="Courier">handleEvent</FONT></TT> method in the
1.0 release of Java.
<HR>
<BLOCKQUOTE>
<B>Listing 9.1. The key press portion of the </B><TT><B><FONT FACE="Courier">handleEvent</FONT></B></TT><B>
method.<BR>
</B>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public boolean handleEvent(Event evt)
{<BR>
&nbsp;&nbsp;switch (evt.id) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;...<BR>
&nbsp;&nbsp;case Event.KEY_PRESS:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;return keyDown(evt, evt.key);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;...<BR>
&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;return false;<BR>
}</FONT></TT>
</BLOCKQUOTE>
<HR>
<P>
The handling of other system events is very similar to that of
the <TT><FONT FACE="Courier">KEY_PRESS</FONT></TT> event. You
could easily override <TT><FONT FACE="Courier">handleEvent</FONT></TT>
to provide custom routing of event handlers, but it is rarely
necessary. Although you might not ever need to intervene with
the default event handling provided by <TT><FONT FACE="Courier">handleEvent</FONT></TT>,
it is nevertheless important to understand how it works.
<H2><A NAME="KeyboardEvents"><B><FONT SIZE=5 COLOR=#FF0000>Keyboard
Events</FONT></B></A><BR>
</H2>
<P>
Java keyboard events are generated when the user presses or releases
a key. Two standard keyboard event handler methods are supported
by the <TT><FONT FACE="Courier">Component</FONT></TT> class: <TT><FONT FACE="Courier">keyDown</FONT></TT>
and <TT><FONT FACE="Courier">keyUp</FONT></TT>. These two methods
are defined as follows:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public boolean keyDown(Event evt, int
key)<BR>
public boolean keyUp(Event evt, int key)</FONT></TT>
</BLOCKQUOTE>
<P>
The <TT><FONT FACE="Courier">keyDown</FONT></TT> method is called
in response to the user pressing a key, and the <TT><FONT FACE="Courier">keyUp</FONT></TT>
method is called in response to the user releasing a key. Both
methods are passed an <TT><FONT FACE="Courier">Event</FONT></TT>
object and an integer key value parameter. The key value parameter,
<TT><FONT FACE="Courier">key</FONT></TT>, specifies which key
was pressed or released. The <TT><FONT FACE="Courier">Event</FONT></TT>
object parameter contains extra information relating to the keyboard
event, such as whether the Shift key was held down when the key
was pressed.
<P>
The <TT><FONT FACE="Courier">Event</FONT></TT> object contains
constants representing the different keys that can be specified
in the <TT><FONT FACE="Courier">key</FONT></TT> parameter. Table
9.1 shows a list of the more useful key constants.<BR>
<BLOCKQUOTE>
<CENTER><B>Table 9.1. Useful key constants for games.</B></CENTER>
</BLOCKQUOTE>
<P>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><I>Constant</I></TD><TD WIDTH=103><I>Key</I>
</TD></TR>
<TR><TD WIDTH=78><TT><FONT FACE="Courier">UP</FONT></TT></TD>
<TD WIDTH=103>Up arrow</TD></TR>
<TR><TD WIDTH=78><TT><FONT FACE="Courier">DOWN</FONT></TT></TD>
<TD WIDTH=103>Down arrow</TD></TR>
<TR><TD WIDTH=78><TT><FONT FACE="Courier">LEFT</FONT></TT></TD>
<TD WIDTH=103>Left arrow</TD></TR>
<TR><TD WIDTH=78><TT><FONT FACE="Courier">RIGHT</FONT></TT></TD>
<TD WIDTH=103>Right arrow</TD></TR>
<TR><TD WIDTH=78><TT><FONT FACE="Courier">HOME</FONT></TT></TD>
<TD WIDTH=103>Home</TD></TR>
<TR><TD WIDTH=78><TT><FONT FACE="Courier">END</FONT></TT></TD>
<TD WIDTH=103>End</TD></TR>
<TR><TD WIDTH=78><TT><FONT FACE="Courier">PGUP</FONT></TT></TD>
<TD WIDTH=103>Page Up</TD></TR>
<TR><TD WIDTH=78><TT><FONT FACE="Courier">PGDN</FONT></TT></TD>
<TD WIDTH=103>Page Down</TD></TR>
</TABLE></CENTER>
<P>
<P>
To check whether the key pressed or released is one of these keys,
you override <TT><FONT FACE="Courier">keyDown</FONT></TT> or <TT><FONT FACE="Courier">keyUp</FONT></TT>
and compare the value of <TT><FONT FACE="Courier">key</FONT></TT>
to one of the constants. Listing 9.2 contains an example of overriding
<TT><FONT FACE="Courier">keyDown</FONT></TT> to check for the
user pressing one of the arrow keys.
<HR>
<BLOCKQUOTE>
<B>Listing 9.2. Handling arrow key presses in the </B><TT><B><FONT FACE="Courier">keyDown</FONT></B></TT><B>
method.<BR>
</B>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public boolean keyDown(Event evt, int
key) {<BR>
&nbsp;&nbsp;switch (key) {<BR>
&nbsp;&nbsp;case Event.LEFT:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;// left arrow key pressed<BR>
&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>
&nbsp;&nbsp;case Event.RIGHT:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;// right arrow key pressed<BR>
&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>
&nbsp;&nbsp;case Event.UP:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;// up arrow key pressed<BR>
&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>
&nbsp;&nbsp;case Event.DOWN:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;// down arrow key pressed<BR>
&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>
&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;return true;<BR>
}</FONT></TT>
</BLOCKQUOTE>
<HR>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91蜜桃免费观看视频| 色老综合老女人久久久| 亚洲品质自拍视频| 精品久久五月天| 在线免费观看日韩欧美| 国产麻豆午夜三级精品| 日韩精品电影一区亚洲| 国产精品视频麻豆| 国产嫩草影院久久久久| 在线精品国精品国产尤物884a| 极品美女销魂一区二区三区| 亚洲一二三级电影| 国产精品福利一区| 欧美成人性战久久| 欧美精选在线播放| 色婷婷久久一区二区三区麻豆| 黄色精品一二区| 首页国产丝袜综合| 亚洲男人都懂的| 日本一区二区免费在线观看视频 | 在线观看一区日韩| 不卡电影免费在线播放一区| 经典三级在线一区| 人禽交欧美网站| 亚洲成人三级小说| 亚洲综合色视频| 亚洲区小说区图片区qvod| 国产网站一区二区三区| 久久精品久久综合| 国产精品嫩草99a| 26uuu国产一区二区三区| 91精品国产入口在线| 在线观看日韩精品| 日本精品一区二区三区高清| av影院午夜一区| 成人动漫中文字幕| 97久久精品人人爽人人爽蜜臀| 国产精品一区二区在线播放 | 中文字幕国产一区| 日本一区二区三区国色天香| 欧美国产禁国产网站cc| 国产日韩欧美制服另类| 国产亚洲欧美色| 日本一二三四高清不卡| 国产精品午夜免费| 成人欧美一区二区三区| 亚洲视频免费在线观看| 亚洲欧美日韩一区二区| 伊人性伊人情综合网| 一区二区视频在线| 亚洲国产va精品久久久不卡综合| 亚洲成人先锋电影| 美女在线视频一区| 国产精品羞羞答答xxdd| 99久久免费国产| 91国偷自产一区二区使用方法| 91久久精品午夜一区二区| 欧美日韩综合在线免费观看| 91精品国产品国语在线不卡| 精品久久人人做人人爱| 国产精品久久久久一区二区三区共| 国产精品久久久久影院色老大| 一区二区久久久久久| 日韩国产一二三区| 国产酒店精品激情| 一本到不卡免费一区二区| 亚洲精品免费视频| 在线观看区一区二| 欧美日韩美女一区二区| 欧美一级片在线看| 国产精品网站在线观看| 亚洲激情一二三区| 激情另类小说区图片区视频区| 成人综合在线视频| 欧美色爱综合网| 国产亚洲福利社区一区| 中文字幕一区二区三区四区| 亚洲成va人在线观看| 韩国欧美一区二区| 色视频一区二区| 亚洲精品一区二区三区精华液 | 日本少妇一区二区| 大胆亚洲人体视频| 91精选在线观看| 国产精品日韩精品欧美在线| 午夜久久电影网| 粉嫩一区二区三区在线看| 欧美三级视频在线观看| 久久久精品天堂| 天堂成人免费av电影一区| 粉嫩嫩av羞羞动漫久久久| 欧美日韩精品一区二区三区四区 | 久久精品99国产精品日本| av在线这里只有精品| 欧美一区二区在线免费播放| 国产精品青草久久| 日本vs亚洲vs韩国一区三区| 色狠狠色狠狠综合| 国产日产欧美一区二区三区 | 91在线视频播放地址| 日韩一卡二卡三卡| 亚洲综合999| 成人丝袜高跟foot| 精品美女被调教视频大全网站| 亚洲欧美偷拍卡通变态| 国产老肥熟一区二区三区| 欧美精品视频www在线观看| 国产精品国产三级国产a| 国产剧情一区二区| 精品国产乱码91久久久久久网站| 亚洲成人动漫av| 91视频国产观看| 国产精品乱码一区二区三区软件| 美女一区二区视频| 欧美一区二区三区白人| 一区二区三区免费观看| av激情成人网| 国产精品视频一二三| 国产麻豆视频精品| 精品国产伦理网| 青青草国产精品亚洲专区无| 欧美日韩国产另类不卡| 亚洲一二三区视频在线观看| 色先锋久久av资源部| 中文字幕一区日韩精品欧美| 国产成人一区在线| 国产欧美一区二区精品忘忧草| 国产精品69毛片高清亚洲| 欧美精品一区二区蜜臀亚洲| 美腿丝袜亚洲三区| 精品久久一区二区| 国产一区在线观看视频| 久久久精品tv| 成人激情小说乱人伦| 国产精品久久久久久久久免费丝袜| 国内欧美视频一区二区| 久久人人爽人人爽| 成人黄色一级视频| 亚洲人成在线播放网站岛国| 91小视频免费观看| 亚洲精品免费一二三区| 欧美日韩精品系列| 婷婷激情综合网| 欧美一区二区啪啪| 精品一二线国产| 欧美极品美女视频| 99re成人精品视频| 亚洲成人av一区| 日韩丝袜美女视频| 国产综合成人久久大片91| 久久精品在线免费观看| 不卡免费追剧大全电视剧网站| 亚洲图片你懂的| 欧美日韩精品久久久| 日韩中文字幕不卡| 久久久国产一区二区三区四区小说| 国产成人鲁色资源国产91色综| 中文字幕在线观看一区二区| 色综合久久久久久久| 丝袜a∨在线一区二区三区不卡| 欧美成人欧美edvon| 成人免费视频播放| 亚洲一级二级在线| 精品av综合导航| 99久久夜色精品国产网站| 亚洲综合久久久久| 26uuu亚洲综合色欧美| voyeur盗摄精品| 午夜精品久久久久久久99水蜜桃 | 中文字幕在线免费不卡| 欧美视频在线播放| 国产一区二区在线免费观看| 国产精品国产自产拍高清av王其| 欧亚洲嫩模精品一区三区| 精品一区免费av| 亚洲精品一二三| 日韩欧美国产综合一区| 93久久精品日日躁夜夜躁欧美| 视频一区二区欧美| 欧美激情中文字幕一区二区| 欧美日韩国产精选| 丁香婷婷综合五月| 视频一区二区三区中文字幕| 欧美经典一区二区三区| 欧美人与性动xxxx| gogogo免费视频观看亚洲一| 日韩国产欧美在线观看| 中文字幕一区二区不卡| 日韩欧美一级精品久久| 91免费观看视频在线| 久久99精品网久久| 亚洲一区二区三区在线播放| 国产女人18水真多18精品一级做| 欧美日韩国产首页| 99国产精品久久久久久久久久| 青青草原综合久久大伊人精品优势 | 亚洲欧洲99久久| 精品欧美一区二区在线观看| 欧美色精品天天在线观看视频| 成人av电影在线播放|