Java程序设计教案(第五章)_第1页
Java程序设计教案(第五章)_第2页
Java程序设计教案(第五章)_第3页
Java程序设计教案(第五章)_第4页
Java程序设计教案(第五章)_第5页
已阅读5页,还剩14页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

教案纸教案纸 第第 5 章章 Java 的的图图形形用用户户界界面面 6 学学时时 主要讲授内容及时间分配 5 1 图形用户界面概述 25 分钟 5 2 AWT 中常用类的层次结构 20 分钟 5 3 基本组件的使用 45 分钟 5 4 布局管理器 45 分钟 5 5 事件处理 90 分钟 5 6 菜单 绘图类的使用 45 分钟 重点与难点 1 重点 1 基本组件的使用 包括 Label Button TextField TextArea List Checkbox 和 CheckboxGroup 的构造方法和常用方法的使用 2 布局管理器的使用 包括 FlowLayout GridLayout BorderLayout 3 事件处理 2 难点 事件处理 教学要求 1 可以构造出图形用户界面 2 可以为界面上的组件编写相应的事件处理代码 3 可以构造带有菜单的应用程序 4 可以写小游戏 实施方法 课堂讲授 PPT 配合 5 3 基本组件的使用基本组件的使用 1 Label 类类 import java awt public class LabelDemo extends Frame public LabelDemo Label lb1 lb2 lb3 lb1 new Label LeftLabel lb2 new Label CenterLabel Label CENTER lb3 new Label RightLabel Label RIGHT lb3 setText 改变我的名字 lb3 setAlignment Label CENTER lb3 setVisible false setLayout new FlowLayout add lb1 add lb2 add lb3 public static void main String args LabelDemo Ld new LabelDemo Ld setVisible true Ld pack 2 Button 类类 import java awt public class MyButtons public static void main String args Frame f new Frame f setLayout new FlowLayout Button button1 new Button Ok Button button2 new Button Open Button button3 new Button Close f add button1 f add button2 f add button3 f setSize 300 100 f setVisible true 3 CheckBox 类类 import java awt public class CheckboxDemo2 extends Frame public CheckboxDemo2 setLayout new FlowLayout String University Tsinghua Pecking Fudan Nanki Tianjin Checkbox c new Checkbox 5 Label label new Label There are 5 University Label label2 new Label There are 5 University Label label3 new Label There are 5 University add new Label Please choice the University for int i 0 i 5 i c i new Checkbox University i add c i add label add label2 add label3 this pack show public static void main String args CheckboxDemo2 cbd new CheckboxDemo2 cbd setSize 400 500 4 CheckBoxGroup 类类 import java awt import java awt CheckboxGroup public class CheckboxGroupDemo2 extends Frame public CheckboxGroupDemo2 super CheckboxGroupDemo2 setLayout new FlowLayout String University Tsinghua Pecking Fudan Nanki Tianjin Checkbox c new Checkbox 5 Label label new Label There are 5 University CheckboxGroup d new CheckboxGroup add new Label Please choice the University for int i 0 i 0 handleDel list getSelectedIndex else if e getSource up else if e getSource down else if e getSource list taskInput setText list getSelectedItem taskInput requestFocus private void handleAdd String newTask list add newTask list select list getItemCount 1 taskInput setText private void handleDel int pos list remove pos list select pos private void handleIncPriority int pos String item list getItem pos list remove pos list add item pos 1 list select pos 1 private void handleDecPriority int pos if poscage getSize width x cage getSize width xdir 1 if xcage getSize height y cage getSize height ydir 1 if y 0 ydir 1 public void draw Graphics g g drawImage bird x y 30 30 cage Cage 类 import java awt import java awt event public class Cage extends Frame implements ActionListener private Button quit new Button Quit private Button start new Button Start private Button stop new Button Stop private Bird birds new Bird 20 Image bird Toolkit getDefaultToolkit getImage qq jpg public Cage super Cage with Birds setLayout new FlowLayout add quit quit addActionListener this add start start addActionListener this add stop stop addActionListener this setSize 400 500 this setVisible true for int i 0 i birds length i int x int getSize width Math random int y int getSize height Math random birds i new Bird this x y public void actionPerformed ActionEvent e if e getSource stop for int i 0 i birds length i birds i halt if e getSource start for int i 0 i birds length i birds i halt birds i new Bird this birds i x birds i y if e getSource quit System exit 0 public void paint Graphics g for int i 0 i birds length i if birds i null birds i draw g public static void main String args Cage table new Cage DrawWithCanvas import java applet import java awt public class DrawWithCanvas extends Frame private Button draw new Button Draw private DrawCanvas canvas new DrawCanvas public DrawWithCanvas Panel panel new Panel panel setLayout new FlowLayout panel add draw setLayout new BorderLayout add North panel add South canvas this setSize 400 500 pack show public static void main String args DrawWithCanvas dnc new DrawWithCanvas class DrawCanvas extends Canvas public DrawCanvas this setSize 400 500 public void paint Graphics g for int i 12 i getSize height i 12 g drawString y location is i 10 i DrawNoCanvas import java applet import java awt public class DrawNoCanvas extends Frame private Button draw new Button Draw public DrawNoCanvas Panel panel new Panel panel setLayout new F

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论