?? 1.htm
字號:
<html><!-- #BeginTemplate "/Templates/empolder_doc.dwt" -->
<head>
<!-- #BeginEditable "doctitle" -->
<title>|><| 太平洋電腦信息網 -> 網絡學院 -> 開發教室</title>
<!-- #EndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
-->
</style>
<link rel="stylesheet" href="/pcedu/style/text.css"></head>
<body bgcolor="#FFFFFF" topmargin=0 leftmargin=0 marginheight="0">
<script language="JavaScript" src="/pcedu/script/top.js">
</script>
<table width=760 border=0 cellspacing=0 cellpadding=0 align=center>
<tr>
<td width=194 height="56"><a href=http://www.pconline.com.cn><img src=http://www.pconline.com.cn/images/pconlinelogo.gif width=162 height=35 vspace=10 border=0></a></td>
<td width=406 height="56">
<script language="JavaScript" src="/pcedu/script/empolder_ad.js">
</script>
</td>
<td width=158 align=right height="56">
<script language="JavaScript" src="/pcedu/script/empolder_ad1.js">
</script>
</td>
<td align=right width=2 height="56"> </td>
</tr>
</table>
<table border=0 cellpadding=0 cellspacing=0 width=760 align="center">
<tbody>
<tr valign=bottom>
<td rowspan=2 width=172><img height=32 src="/pcedu/images/pcedu_lo.gif"
width=172 border="0"></td>
<td height=30 rowspan=2>
<table cellpadding=0 cellspacing=0 width="588" bgcolor="#FFA000" background="/pcedu/images/e_menu5.gif" border="0">
<tbody>
<tr valign="bottom">
<td height="17">
<script language="JavaScript" src="/pcedu/script/title_empolder.js">
</script>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr bgcolor="#303880">
<td colspan=2 height=1 valign=bottom><img height=1
src="/pcedu/images/blank.gif" width=1></td>
</tr>
<tr>
<td colspan=2 height=5 valign=bottom><img height=5
src="/pcedu/images/blank.gif" width=1></td>
</tr>
</tbody>
</table>
<table width="760" cellspacing="0" cellpadding="0" align="center" height="37">
<tr>
<td width="170" valign="top">
<table border="0" width="170" height="100%"
cellspacing="1" bgcolor="#000000">
<tr bgcolor="#F8F8D2">
<td width="100%" valign="top"><!-- #BeginEditable "left" -->
<div align="center">
<table width="100%" border="0" cellspacing="1" cellpadding="0" bgcolor="#000000" align="center">
<tr bgcolor="#E17329">
<td height="20" align="center"><font color="#FFFFFF">==<b>開發教室==</b></font></td>
</tr>
</table>
<br>
</div>
<!-- #EndEditable -->
<script language="JavaScript" src="/pcedu/script/left_empolder.js">
</script>
</td>
</tr>
</table>
</td>
<td width="10"><img src="/pcedu/images/blank.gif" width="1" height="1"></td>
<td width="580" valign="top" class="article">
<p><img src="/pcedu/images/666666.gif" width="99%" height="1"></p>
<!-- #BeginEditable "content" -->
<p align="center"><span class="title">Java Applet 入門</span></p>
<p align="right"><a href="mailto:yy435@263.net">yy435</a></p>
<p align="right">太平洋網絡學院</p>
<p align="center" class="green">第四天</p>
<p align="left" class="green">鼠標和鍵盤事件處理函數</p>
<p>所謂事件,就是指在系統中有某些我們所關心的事情(例如:鼠標移動了,用戶按下了某個按鍵……等)發生了,然后系統便通知我們去處理這些事情。這樣的概念在一般采用窗口用戶界面環境的操作系統中,是十分常見的。</p>
<p>在Java中,所有的事件都定義在類Event(java.awt.Event)內,讀者有興趣的話,可以參考Java的API。</p>
<p><font color="#66FF66">1)鼠標事件。</font></p>
<p>鼠標時間一般有:<br>
<font color="#FF9966">mouseDown:</font>當鼠標的按鍵被用戶按下時,就會發生MOUSE_DOWN時間,這個時候系統便調用方法mouseDown對該事件進行處理。方法mouseDown的寫法為:</p>
<p>public boolean mouseDown(Event e,int x,int y)<br>
{<br>
……<br>
}</p>
<p>由上面可知,方法mouseDown有三個參數:e,x,y。e就是事件本身,我們把“事件”看成一個對象實體,只不過它的類是Event而已,同時,事件在使用上和一般的對象實體沒有差別。而x,y則是這個時間發生時的鼠標的坐標值。要注意的是它的方法返回值是boolean型的值,這點要注意!另外,由于有些機器的鼠標只有一個按鍵,考慮到Java的與平臺無關性,因此,這個方法中,就沒有我們常見的右鍵的功能了。它不區分左右按鍵。
</p>
<p><font color="#FF9966">mouseUp:</font>與前面的相反,這個方法是鼠標放開時的處理函數了,對于使用方法,與mouseDown完全相同。這兒就不多說了!</p>
<p><font color="#FF9966">mouseMove:</font>MOUSE_MOVE和MOUSE_DRAG都是由鼠標移動產生的事件,方法mouseMove就是用來處理MOUSE_MOVE事件的。方法為:</p>
<p>public boolean mouseMove(Event evt,int x,int y)<br>
{<br>
…… <br>
}</p>
<p>所用到的參數和方法mouseDown和mouseUp的完全一樣。</p>
<p><font color="#FF9966">mouseDrag:</font>從上面知道,這個方法當然是用來處理MOUSE_DRAG事件的。方法為:</p>
<p>public boolean mouseDrag(Event e,int x,int y)<br>
{<br>
……<br>
}</p>
<p><font color="#FF9966">mouseEnter:</font>這個方法是用來處理MOUSE_ENTER事件的,當鼠標進入到小應用程序的窗口范圍時,就會發生MOUSE_ENTER事件。處理方法為
:</p>
<p>public boolean(Event evt, int x,int y)<br>
{<br>
……<br>
}</p>
<p>所用到的參數和前面一樣,不多說了。</p>
<p><font color="#FF9966">mouseExit:</font>這個方法是用來處理MOUSE_EXIT事件的。當鼠標從小應用程序窗口移出來的時候,就會發生MOUSE_EXIT事件了。處理方法為:</p>
<p>public boolean (Event e,int x,int y)<br>
{<br>
……<br>
} </p>
<p>好了,讓我們來看一看具體的例子:[<a style="text-decoration: none"href="#" onclick="window.open('11.htm','1','menubar=no,toolbar=1,location=no,directories=no,status=no,resizable=1,scrollbars=1,width=780,height=440,top=20,left=10');">請點擊這兒進入</a>]</p>
<p><font color="#99FF99">2)鍵盤事件:</font><br>
和鼠標比起來,鍵盤產生的時間就簡單多了,一般說來,我們關心的就是用戶按下了什么鍵,再處理就行了,而不必像鼠標那樣還具有移動的事件要處理。它的主要事件有:</p>
<p>KEY_PRESS:按下鍵時產生;<br>
KEY_RELEASE:放開鍵盤按鍵的時候產生。處理它們方法方法分別為:</p>
<p> public boolean keyDown(Event evt,int x,int y)<br>
{<br>
……<br>
}</p>
<p>public loolean keyUp(Event evt,int x,int y)<br>
{<br>
……<br>
}</p>
<p>參數中的evt還是表示事件本身的對象,而key就是那個被用戶按下或放開的案件。Java已經在類Event中,定義好一些表轉的按鍵值,如下:</p>
<table width="100%" border="1" bordercolor="#000000">
<tr>
<td width="112"><font color="#000000">類變量</font></td>
<td width="174"><font color="#000000">代表的按鍵</font></td>
<td width="143"><font color="#000000">類變量</font></td>
<td width="143"><font color="#000000">代表的按鍵</font></td>
</tr>
<tr>
<td width="112"><font color="#000000">Event.Up</font></td>
<td width="174"><font color="#000000">方向鍵中的“上”鍵</font></td>
<td width="143"><font color="#000000">Event.F3</font></td>
<td width="143"><font color="#000000">“F3”鍵</font></td>
</tr>
<tr>
<td width="112"><font color="#000000">Event.DOWN</font></td>
<td width="174"><font color="#000000">方向鍵中的“下”鍵</font></td>
<td width="143"><font color="#000000">Event.F4</font></td>
<td width="143"><font color="#000000">“F4”鍵</font></td>
</tr>
<tr>
<td width="112"><font color="#000000">Event.LEFT</font></td>
<td width="174"><font color="#000000">方向鍵中的“左”鍵</font></td>
<td width="143"><font color="#000000">Event.F5</font></td>
<td width="143"><font color="#000000">“F5”鍵</font></td>
</tr>
<tr>
<td width="112"><font color="#000000">Event.RIGHT</font></td>
<td width="174"><font color="#000000">方向鍵中的“右”鍵</font></td>
<td width="143"><font color="#000000">Event.F6</font></td>
<td width="143"><font color="#000000">“F6”鍵</font></td>
</tr>
<tr>
<td width="112"><font color="#000000">Event.HOME</font></td>
<td width="174"><font color="#000000">“Home”鍵</font></td>
<td width="143"><font color="#000000">Event.F7</font></td>
<td width="143"><font color="#000000">“F7”鍵</font></td>
</tr>
<tr>
<td width="112"><font color="#000000">Event.END</font></td>
<td width="174"><font color="#000000">“End”鍵</font></td>
<td width="143"><font color="#000000">Event.F8</font></td>
<td width="143"><font color="#000000">“F8”鍵</font></td>
</tr>
<tr>
<td width="112"><font color="#000000">Event.PGUP</font></td>
<td width="174"><font color="#000000">“Page Up”鍵</font></td>
<td width="143"><font color="#000000">Event.F9</font></td>
<td width="143"><font color="#000000">“F9”鍵</font></td>
</tr>
<tr>
<td width="112"><font color="#000000">Event.PGDN</font></td>
<td width="174"><font color="#000000">“Page Down”鍵</font></td>
<td width="143"><font color="#000000">Event.F10</font></td>
<td width="143"><font color="#000000">“F10”鍵</font></td>
</tr>
<tr>
<td width="112"><font color="#000000">Event.F1</font></td>
<td width="174"><font color="#000000">“F1”鍵</font></td>
<td width="143"><font color="#000000">Event.F11</font></td>
<td width="143"><font color="#000000">“F11”鍵</font></td>
</tr>
<tr>
<td width="112"><font color="#000000">Event.F2</font></td>
<td width="174"><font color="#000000">“F2”鍵</font></td>
<td width="143"><font color="#000000">Event.F12</font></td>
<td width="143"><font color="#000000">“F12”鍵</font></td>
</tr>
</table>
<p align="center"><a href="../03/16.htm">[上一頁]</a> <a href="11.htm">[下一頁]</a></p>
<!-- #EndEditable -->
<div align="center">
<table width="100%" border="0">
<tr class="sfont">
<td>
<div align="center"><a href="javascript:history.go(-1)">[返回]</a>
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<hr noshade size="2" width="760">
<div align="center">
<p align="center"><font color="#000000">
<script language="JavaScript" src="/pcedu/script/title_edu.js">
</script>
</font> <br>
<br>
版權所有©2000 太平洋電腦網<br>
<font face="Arial, Helvetica, sans-serif">
<script>
document.write("<a href=http://best.netease.com/cgi-bin/view/viewbasic.cgi?exp target=_blank><img src=http://best.netease.com/cgi-bin/log.cgi?user=exp&refer="+escape(document.referrer)+"&cur="+escape(document.URL)+" border=0 alt='網易中文排行榜' width=1 height=1></a>");
</script>
<a href=mailto:webmaster@pconline.com.cn> </a></font><font face="Arial, Helvetica, sans-serif"><a href=mailto:webmaster@pconline.com.cn>webmaster@pconline.com.cn</a></font><font face="Arial, Helvetica, sans-serif"><a href=mailto:webmaster@pconline.com.cn>
<script language="">document.write("<a href=http://best.netease.com/cgi-bin/view/viewbasic.cgi?pconline1 target=_blank><img src=http://best.netease.com/cgi-bin/log.cgi?user=pconline1&refer="+escape(document.referrer)+"&cur="+escape(document.URL)+" border=0 width=1 height=1 ></a>");</script>
</a>
<script language="">
document.write("<a href=http://www0.pconline.com.cn:8810/pccount/index.php target=_blank><img src=http://www0.pconline.com.cn:8810/cgi-bin/test.cgi?user=pcedu&refer="+escape(document.referrer)+"&cur="+escape(document.URL)+" border=0 width=0 height=0 alt='' ></a>");
</script>
</font> </p>
</div>
</body>
<!-- #EndTemplate --></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -