中国高校课件下载中心 》 教学资源 》 大学文库

海南大学:《Java语言程序设计》课程电子教案(PPT教学课件)第九章 创建用户界面

文档信息
资源类别:文库
文档格式:PPT
文档页数:53
文件大小:327KB
团购合买:点击进入团购
内容简介
海南大学:《Java语言程序设计》课程电子教案(PPT教学课件)第九章 创建用户界面
刷新页面文档预览

第九章创建用户界面 ■课程内容:JavaBean介绍、组件(文本输入、 选择组件、菜单、对话框等)使用 ■授课时间:2006/04/26 ■教学目标:了解和掌握Swing中的各种常用用 户界面组件的使用 ■ 重点:Swing?组件的使用 ■教学方法:讲授 ■教学过程:(省略) ©2006计算机系杨厚群 All rights lefts reserved

©2006 计算机系 杨厚群 All rights & lefts reserved. 课程内容: JavaBean介绍、组件(文本输入、 选择组件、菜单、对话框等)使用 授课时间:2006/04/26 教学目标:了解和掌握Swing中的各种常用用 户界面组件的使用 重点:Swing组件的使用 教学方法:讲授 教学过程:(省略) 第九章 创建用户界面

JavaBean是什么 JavaBean组件是Java类,适应下面的需求 class Data members JavaBean 至少需要 Methods Constructors public class default public constructor serializable may have accessor methods 可选 may have registration methods ©2006计算机系杨厚群 All rights lefts reserved

©2006 计算机系 杨厚群 All rights & lefts reserved. JavaBean组件是Java 类,适应下面的需求 JavaBean 是什么 Data members Methods Constructors public class default public constructor serializable may have accessor methods may have registration methods class JavaBean 至少需要 可选

为什么使用JavaBeans JavaBeans能使开发人员在设计阶段通过组 装对象迅速构建各种应用,能更有效地实现 代码重用 ©2006计算机系杨厚群 All rights lefts reserved

©2006 计算机系 杨厚群 All rights & lefts reserved. 为什么使用 JavaBeans JavaBeans 能使开发人员在设计阶段通过组 装对象迅速构建各种应用,能更有效地实现 代码重用

JComponent属性 toolTipText font background foreground doubleBuffered border ■preferredSize minimumSize ■maximumSize ©2006计算机系杨厚群 All rights lefts reserved

©2006 计算机系 杨厚群 All rights & lefts reserved. JComponent 属性 toolTipText font background foreground doubleBuffered border preferredSize minimumSize maximumSize

JButton Button组件在被点击时触发一个动作事件。下 面是JButton的非缺省构造函数: JButton(String text) JButton(String text,Iconicon) JButton(Icon icon) 范例:使用Buttons 源码 ©2006计算机系杨厚群 All rights &lefts reserved

©2006 计算机系 杨厚群 All rights & lefts reserved. Button 组件在被点击时触发一个动作事件。下 面是JButton 的非缺省构造函数: JButton(String text) JButton(String text, Icon icon) JButton(Icon icon) 范例: 使用 Buttons 源码 JButton

JButton属性 ■text ■icon mnemonic horizontalAlignment verticalAlignment horizontalTextPosition verticalTextPosition ©2006计算机系杨厚群 All rights lefts reserved

©2006 计算机系 杨厚群 All rights & lefts reserved. JButton 属性 text icon mnemonic horizontalAlignment verticalAlignment horizontalTextPosition verticalTextPosition

JButton事件响应 public void actionPerformed(ActionEvent e) f /Get the button label String actionCommand e.getActionCommand(); /Make sure the event source is a button if (e.getSource()instanceof JButton) /Make sure it is the right button if (My Button".equals (actionCommand) System.out.println (Button pressed!); } ©2006计算机系杨厚群 All rights lefts reserved

©2006 计算机系 杨厚群 All rights & lefts reserved. JButton 事件响应 public void actionPerformed(ActionEvent e) { // Get the button label String actionCommand = e.getActionCommand(); // Make sure the event source is a button if (e.getSource() instanceof JButton) // Make sure it is the right button if ("My Button".equals(actionCommand) System.out.println ("Button pressed!"); }

JLabel label是短文本或图像的显示区域,没有修饰,不响应 用户输入。下面是非缺省的labels构造函数: JLabel(String text,int horizontalAlignment) JLabel(String text) JLabel(Icon icon) JLabel(Iconicon,int horizontalAlignment) 范例:使用Labels 源码 ©2006计算机系杨厚群 All rights lefts reserved

©2006 计算机系 杨厚群 All rights & lefts reserved. label 是短文本或图像的显示区域,没有修饰,不响应 用户输入。下面是非缺省的 labels 构造函数: JLabel(String text, int horizontalAlignment) JLabel(String text) JLabel(Icon icon) JLabel(Icon icon, int horizontalAlignment) 范例:使用 Labels 源码 JLabel

JLabel属性 text ■1con horizontalAlignment verticalAlignment ©2006计算机系杨厚群 All rights lefts reserved

©2006 计算机系 杨厚群 All rights & lefts reserved. text icon horizontalAlignment verticalAlignment JLabel 属性

JTextField text field允许用户输入字符 范例:使用Text Fields 源码 ©2006计算机系杨厚群 All rights lefts reserved

©2006 计算机系 杨厚群 All rights & lefts reserved. text field 允许用户输入字符 范例: 使用 Text Fields 源码 JTextField

刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档