📄 builder_course_109_1_gjbc.html
字号:
</tr>
<tr>
<td colspan="3" align="left" valign="top">
<hr>正 文:<br>
<font class="a"><center><b>你 对 鼠 标 做 了 什 么</b></center><p align="right">作 者 : 清 华 大 学 教 授 : 王 克 宏<p><p>
<font COLOR="#0000AA" SIZE="+1"><b>交 互 的 Java 世 界</b></font>
<ul>
<li>鼠 标 引 发 的 各 种 事 件
<li>编 写 自 己 的 事 件 处 理 代 码
<li>键 盘 引 发 的 事 件
<li>在 Internet 上 实 现 与 程 序 的 实 时 交 互
</ul>
<p><img src="../main/images/blank.gif" tppabs="http://www.chinabyte.com/images/blank.gif" width="30" height="1" border="0">
也 许 你 要 问 “ Java 怎 么 知 道 我 点 了 鼠 标 ? 按 了 哪 个 键 ? ” 它 当 然 知 道 。 你 对 鼠 标 或 键 盘 的 如 何 操 作 对 Java 而 言 都 称 之 为 “ 事 件 ” , 例 如 : 移 动 鼠 标 , 点 击 鼠 标 , 按 下 某 个 按 键 … … 。 这 些 事 件 发 生 了 以 后 , 系 统 就 会 通 知 Java 去 处 理 , 就 好 比 你 按 了 门 铃 , 让 主 人 来 为 你 开 门 一 样 。 在 这 一 章 里 , 你 将 学 会 编 写 这 种 交 互 式 的 程 序 来 响 应 鼠 标 和 键 盘 的 输 入 , 让 Java 干 你 想 让 它 干 的 事 情 。 你 可 以 让 它 告 诉 你 当 前 鼠 标 所 处 的 位 置 , 拖 动 鼠 标 画 你 想 画 的 东 西 , 或 者 用 键 盘 控 制 Homepage 中 图 形 的 位 置 , 甚 至 可 以 编 一 个 由 鼠 标 控 制 的 小 游 戏 。<p>
<font COLOR="#FF8040" SIZE="+0"><center><b>你 对 鼠 标 做 了 什 么</b></center></font><p><img src="../main/images/blank.gif" tppabs="http://www.chinabyte.com/images/blank.gif" width="30" height="1" border="0">
你 对 鼠 标 所 做 的 任 何 操 作 , 系 统 都 会 产 生 一 个 所 谓 “ 事 件 ” 通 知 Java 。 如 果 鼠 标 被 按 下 , Java 将 得 到 一 个 来 自 系 统 的 通 知 --MOUSE_DOWN 。 那 么 释 放 鼠 标 , 是 不 是 就 是 MOUSE_UP 呢 ? 没 错 , 就 是 这 样 。 可 是 鼠 标 通 常 都 有 两 、 三 个 按 键 , Java 怎 么 知 道 我 按 的 是 哪 一 个 呢 ? 不 用 担 心 , Java 对 所 有 的 鼠 标 按 键 都 一 视 同 仁 , 只 要 你 按 了 键 , MOUSE_DOWN 事 件 就 产 生 , 不 管 按 的 是 哪 一 个 。<p><img src="../main/images/blank.gif" tppabs="http://www.chinabyte.com/images/blank.gif" width="30" height="1" border="0">
对 鼠 标 的 操 作 可 不 仅 仅 是 按 下 或 释 放 , 其 实 用 的 最 多 的 还 是 移 动 鼠 标 。 一 旦 你 移 动 了 鼠 标 , Java 就 会 从 系 统 那 里 得 到 一 个 MOUSE_MOVE 的 通 知 。 鼠 标 移 动 还 有 另 一 种 方 式 , 那 就 是 拖 动 , 它 和 移 动 有 什 么 不 同 呢 ? 移 动 时 并 未 按 鼠 标 按 键 , 它 产 生 的 事 件 是 MOUSE_MOVE 。 如 果 你 移 动 鼠 标 的 同 时 还 按 住 了 鼠 标 按 键 , 这 就 是 拖 动 , 它 产 生 的 事 件 将 不 再 是 MOUSE_MOVE , 而 是 MOUSE_DRAG 了 。<p><img src="../main/images/blank.gif" tppabs="http://www.chinabyte.com/images/blank.gif" width="30" height="1" border="0">
Java Applet 对 鼠 标 的 动 作 可 以 非 常 敏 感 , 只 要 鼠 标 进 入 Applet 窗 口 的 范 围 , 它 就 会 有 所 反 应 , 这 是 通 过 MOUSE_ENTER 实 现 的 , MOUSE_ENTER 表 示 鼠 标 指 针 进 入 到 Applet 的 范 围 , 反 之 , MOUSE_EXIT 就 是 鼠 标 离 开 时 产 生 的 事 件 了 。<p><img src="../main/images/blank.gif" tppabs="http://www.chinabyte.com/images/blank.gif" width="30" height="1" border="0">
你 也 许 要 奇 怪 了 , “ 前 面 编 了 这 么 多 Java 程 序 , 我 对 鼠 标 作 了 这 么 多 操 作 , 怎 么 都 没 有 反 应 呢 ? ” 当 然 不 会 有 反 应 ! 因 为 系 统 虽 然 通 知 了 Java , 鼠 标 做 了 什 么 , 键 盘 被 按 了 哪 个 键 , 可 是 Java 并 没 有 告 诉 系 统 , 鼠 标 或 键 盘 动 作 了 以 后 应 该 作 何 反 应 。 就 好 像 门 铃 响 了 , 你 知 道 去 开 门 ; 电 话 铃 响 了 , 应 该 接 电 话 。 我 们 也 可 以 通 过 自 己 编 写 的 Java 程 序 , 告 诉 系 统 对 鼠 标 、 键 盘 的 操 作 做 出 相 应 的 反 应 。<p><p>
<center>
第1页
<a href="builder_course_109_2_GJBC.html" tppabs="http://www.chinabyte.com/staticpages/builder/builder_course/GJBC/builder_course_109_2_GJBC.html">第2页</a>
<a href="builder_course_109_3_GJBC.html" tppabs="http://www.chinabyte.com/staticpages/builder/builder_course/GJBC/builder_course_109_3_GJBC.html">第3页</a>
<a href="builder_course_109_4_GJBC.html" tppabs="http://www.chinabyte.com/staticpages/builder/builder_course/GJBC/builder_course_109_4_GJBC.html">第4页</a>
<a href="builder_course_109_5_GJBC.html" tppabs="http://www.chinabyte.com/staticpages/builder/builder_course/GJBC/builder_course_109_5_GJBC.html">第5页</a>
<a href="builder_course_109_6_GJBC.html" tppabs="http://www.chinabyte.com/staticpages/builder/builder_course/GJBC/builder_course_109_6_GJBC.html">第6页</a>
<a href="builder_course_109_2_GJBC.html" tppabs="http://www.chinabyte.com/staticpages/builder/builder_course/GJBC/builder_course_109_2_GJBC.html">下一页</a>
</center>
<p><hr>
</td>
</tr>
<tr>
<td width="400" align="left" valign="top"><br>
<b>参 考 文 章 : </b><br>
<font class="a">1. <a href="builder_course_112_1_GJBC.html" tppabs="http://www.chinabyte.com/staticpages/builder/builder_course/GJBC/builder_course_112_1_GJBC.html">Java应 用 教 程 (八 )—— 例 外 处 理</a> ( 1998-09-02 )</font><br>
<font class="a">2. <a href="builder_course_111_1_GJBC.html" tppabs="http://www.chinabyte.com/staticpages/builder/builder_course/GJBC/builder_course_111_1_GJBC.html">Java应 用 教 程 (七 )—— Java的 网 络 功 能</a> ( 1998-08-03 )</font><br>
<font class="a">3. <a href="builder_course_110_1_GJBC.html" tppabs="http://www.chinabyte.com/staticpages/builder/builder_course/GJBC/builder_course_110_1_GJBC.html">Java应 用 教 程 (六 )—— 终 于 动 起 来 了</a> ( 1998-07-03 )</font><br>
<font class="a">4. <a href="builder_course_108_1_GJBC.html" tppabs="http://www.chinabyte.com/staticpages/builder/builder_course/GJBC/builder_course_108_1_GJBC.html">Java应 用 教 程 (四 )—— 五 彩 缤 纷 的 世 界</a> ( 1998-03-11 )</font><br>
<font class="a">5. <a href="builder_course_105_1_GJBC.html" tppabs="http://www.chinabyte.com/staticpages/builder/builder_course/GJBC/builder_course_105_1_GJBC.html">Java应 用 教 程 (三 )—— 漂 亮 的 标 语</a> ( 1998-01-27 )</font><br>
<font class="a">6. <a href="builder_course_104_1_GJBC.html" tppabs="http://www.chinabyte.com/staticpages/builder/builder_course/GJBC/builder_course_104_1_GJBC.html">Java应 用 教 程 (二 )—— 巧 手 木 匠</a> ( 1997-12-16 )</font><br>
<font class="a">7. <a href="builder_course_100_1_GJBC.html" tppabs="http://www.chinabyte.com/staticpages/builder/builder_course/GJBC/builder_course_100_1_GJBC.html">Java应 用 教 程 (一)——美 丽 的 窗 口</a> ( 1997-11-04 )</font><br>
</td>
<td width="20"><img src="../main/images/blank.gif" tppabs="http://www.chinabyte.com/images/blank.gif" border="0" width="20" height="1">
</td>
<td width="204" align="left" valign="top"><br>
<font class="a">
如 果 您 认 为 这 篇 文 章 还 不 错 , 欢 迎 您 向 其 他 读 者 推 荐 ; 如 果 您 认 为 这 篇 文 章 水 平 太 差 , 欢 迎 您 <a href="mailto:buildermaster@chinabyte.com">发 表 高 见</a> 。</font>
</td>
</tr>
</table>
<p>
<table border="0" cellspacing="0" cellpadding="0" bgcolor="#980018">
<tr>
<td bgcolor="ffffff"><img src="../main/images/b_left.gif" tppabs="http://www.chinabyte.com/images/b_left.gif" border="0" WIDTH="19" HEIGHT="27"></td>
<td>
<a href="../tppmsgs/msgs2.htm#250" tppabs="http://www.chinabyte.com/staticpages/feedback/feedback_home/feedback/feedback_home_1.html" onMouseOver="window.status = '服务台'; return true "><img src="../main/images/99feedback.gif" tppabs="http://www.chinabyte.com/images/99feedback.gif" border="0" alt="服务台" WIDTH="39" HEIGHT="27"></a><img src="../main/images/b_1.gif" tppabs="http://www.chinabyte.com/images/b_1.gif" WIDTH="10" HEIGHT="27"><img src="../main/images/b_2.gif" tppabs="http://www.chinabyte.com/images/b_2.gif" WIDTH="11" HEIGHT="27"></td>
<td>
<a href="../tppmsgs/msgs2.htm#251" tppabs="http://www.chinabyte.com/staticpages/siteinfo/siteinfo_mapind/siteinfo/siteinfo_mapind_1.html" onMouseOver="window.status = '站导图'; return true "><img src="../main/images/99site.gif" tppabs="http://www.chinabyte.com/images/99site.gif" border="0" alt="站导图" WIDTH="38" HEIGHT="27"></a><img src="../main/images/b_1.gif" tppabs="http://www.chinabyte.com/images/b_1.gif" WIDTH="10" HEIGHT="27"><img src="../main/images/b_2.gif" tppabs="http://www.chinabyte.com/images/b_2.gif" WIDTH="11" HEIGHT="27"></td>
<td>
<a href="../tppmsgs/msgs2.htm#252" tppabs="http://www.chinabyte.com/feedback/about_chinabyte.html" onMouseOver="window.status = '关于本站'; return true "><img src="../main/images/99about.gif" tppabs="http://www.chinabyte.com/images/99about.gif" border="0" alt="关于本站" WIDTH="52" HEIGHT="27"></a><img src="../main/images/b_1.gif" tppabs="http://www.chinabyte.com/images/b_1.gif" WIDTH="10" HEIGHT="27"><img src="../main/images/b_2.gif" tppabs="http://www.chinabyte.com/images/b_2.gif" WIDTH="11" HEIGHT="27"></td>
<td width="131" bgcolor="#980018"><img src="../main/images/blank.gif" tppabs="http://www.chinabyte.com/images/blank.gif" border="0" width="1" height="1"></td>
<td><a HREF="../tppmsgs/msgs2.htm#200" tppabs="http://www.chinabyte.com/staticpages/digest/digest_home/digest/digest_home_1.html" onMouseOver="window.status = '及时传送IT产业新闻'; return true" target="_top"><img src="../main/images/99news.gif" tppabs="http://www.chinabyte.com/images/99news.gif" border="0" alt="新闻总线" WIDTH="53" HEIGHT="27"></a><img src="../main/images/b_1.gif" tppabs="http://www.chinabyte.com/images/b_1.gif" WIDTH="10" HEIGHT="27"><img src="../main/images/b_2.gif" tppabs="http://www.chinabyte.com/images/b_2.gif" WIDTH="11" HEIGHT="27"></td>
<td><a HREF="../tppmsgs/msgs2.htm#202" tppabs="http://www.chinabyte.com/staticpages/software/software_home/software/software_home_1.html" onMouseOver="window.status = '漫步免费软件仓库'; return true" target="_top"><img src="../main/images/99soft.gif" tppabs="http://www.chinabyte.com/images/99soft.gif" border="0" alt="软件仓库" WIDTH="52" HEIGHT="27"></a><img src="../main/images/b_1.gif" tppabs="http://www.chinabyte.com/images/b_1.gif" WIDTH="10" HEIGHT="27"><img src="../main/images/b_2.gif" tppabs="http://www.chinabyte.com/images/b_2.gif" WIDTH="11" HEIGHT="27"></td>
<td><a HREF="../tppmsgs/msgs2.htm#204" tppabs="http://www.chinabyte.com/staticpages/builder/builder_home/builder/builder_home_1.html" onMouseOver="window.status = '在线专业培训'; return true" target="_top"><img src="../main/images/99_builder.gif" tppabs="http://www.chinabyte.com/images/99_builder.gif" border="0" alt="网络学院" WIDTH="52" HEIGHT="27"></a><img src="../main/images/b_1.gif" tppabs="http://www.chinabyte.com/images/b_1.gif" WIDTH="10" HEIGHT="27"><img src="../main/images/b_2.gif" tppabs="http://www.chinabyte.com/images/b_2.gif" WIDTH="11" HEIGHT="27"></td>
<td><a HREF="../tppmsgs/msgs2.htm#213" tppabs="http://www.chinabyte.com/staticpages/gamecen/gamecen_home/gamecen/gamecen_home_1.html" onMouseOver="window.status = '游戏玩家的乐园'; return true" target="_top"><img src="../main/images/99game.gif" tppabs="http://www.chinabyte.com/images/99game.gif" border="0" alt="游戏天堂" WIDTH="52" HEIGHT="27"></a><img src="../main/images/b_1.gif" tppabs="http://www.chinabyte.com/images/b_1.gif" WIDTH="10" HEIGHT="27"><img src="../main/images/b_2.gif" tppabs="http://www.chinabyte.com/images/b_2.gif" WIDTH="11" HEIGHT="27"></td>
<td><a HREF="../tppmsgs/msgs2.htm#214" tppabs="http://www.chinabyte.com/staticpages/digital/digital_home/digital/digital_home_1.html" onMouseOver="window.status = '数字世界'; return true" target="_top"><img src="../main/images/99digital.gif" tppabs="http://www.chinabyte.com/images/99digital.gif" border="0" alt="数字世界" WIDTH="53" HEIGHT="27"></a><img src="../main/images/b_1.gif" tppabs="http://www.chinabyte.com/images/b_1.gif" WIDTH="10" HEIGHT="27"><img src="../main/images/b_2.gif" tppabs="http://www.chinabyte.com/images/b_2.gif" WIDTH="11" HEIGHT="27"></td>
<td width="30"><img src="../main/images/blank.gif" tppabs="http://www.chinabyte.com/images/blank.gif" border="0" width="1" height="1"></td>
</tr>
</table>
<center><table>
<tr>
<td align="center"><br><font size="-2">
<b>ChinaByte</b>版 权 所 有, 未 经 授 权 禁 止 复 制 或 建 立 镜 像。<br>
如 果 您 有 什 么 问 题, 请 发 <a href="mailto:webmaster@chinabyte.com">电 子 邮 件</a> 给 我 们。 谢 谢! </font>
</td>
</tr>
</table></center>
<!--msnavigation--></td></tr><!--msnavigation--></table></body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -