![23Java GUI程序设计(3).ppt_第1页](http://file1.renrendoc.com/fileroot2/2020-1/10/9cfec64e-37bd-4431-aa3c-1a60e335b45c/9cfec64e-37bd-4431-aa3c-1a60e335b45c1.gif)
![23Java GUI程序设计(3).ppt_第2页](http://file1.renrendoc.com/fileroot2/2020-1/10/9cfec64e-37bd-4431-aa3c-1a60e335b45c/9cfec64e-37bd-4431-aa3c-1a60e335b45c2.gif)
![23Java GUI程序设计(3).ppt_第3页](http://file1.renrendoc.com/fileroot2/2020-1/10/9cfec64e-37bd-4431-aa3c-1a60e335b45c/9cfec64e-37bd-4431-aa3c-1a60e335b45c3.gif)
![23Java GUI程序设计(3).ppt_第4页](http://file1.renrendoc.com/fileroot2/2020-1/10/9cfec64e-37bd-4431-aa3c-1a60e335b45c/9cfec64e-37bd-4431-aa3c-1a60e335b45c4.gif)
![23Java GUI程序设计(3).ppt_第5页](http://file1.renrendoc.com/fileroot2/2020-1/10/9cfec64e-37bd-4431-aa3c-1a60e335b45c/9cfec64e-37bd-4431-aa3c-1a60e335b45c5.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Java GUI程序设计(3),目标,理解事件处理机制 掌握常见事件类型与监听器接口 掌握如何写一个监听器类 掌握注册监听器 掌握事件适配器,委派式事件处理模型,Swing事件模型,事件源对象,事件对象,监听器对象,处理事件,Swing中的GUI组件,发生事件,传递,事件源对象如何知道通知哪个监听器?,在事件源对象上注册监听器 add( listener),事件处理示例,public class HelloFrame extends JFrame JPanel contentPane; BorderLayout borderLayout1 = new BorderLayout(); JButt
2、on jButton1 = new JButton(); JTextField jTextField1 = new JTextField(); public HelloFrame() contentPane = (JPanel) getContentPane(); contentPane.setLayout(borderLayout1); setSize(new Dimension(400, 300); setTitle(Frame Title); jButton1.setText(press me); jButton1.addActionListener(new Frame1_jButton
3、1_actionAdapter(this); contentPane.add(jButton1); setVisible(true); ,/监听器类 class Frame1_jButton1_actionAdapter implements ActionListener private Frame1 adaptee; Frame1_jButton1_actionAdapter(Frame1 adaptee) this.adaptee = adaptee; public void actionPerformed(ActionEvent e) adaptee.jTextField1.setTex
4、t(“you press the button); ,窗口事件,当一个窗口被激活、撤销激活、打开、关闭、最大化、最小化时,发生窗口事件。 从WindowEvent类中创建的对象表示窗口事件。,示例,public class FrameW extends JFrame implements WindowListener public FrameW() this.addWindowListener(this); public void windowClosed(WindowEvent e) public void windowOpened(WindowEvent e) public void wi
5、ndowClosing(WindowEvent e) System.exit(1); public void windowIconified(WindowEvent e) public void windowDeiconified(WindowEvent e) public void windowActivated(WindowEvent e) public void windowDeactivated(WindowEvent e) public static void main(String args) FrameW framew = new FrameW(); framew.setSize
6、(300,200); framew.setVisible(true); ,鼠标事件,当鼠标被点击、按下、抬起、拖动、移动时产生鼠标事件 MouseEvent类的对象表示鼠标事件 处理鼠标事件的类要实现以下接口: MouseListener MouseMotionListener,跟踪多个事件示例,public class TwoListener implements MouseMotionListener, MouseListener private JFrame fr; private JTextField tf; TwoListener() fr=new JFrame(TwoListene
7、r Example); fr.getContentPane().setLayout(new FlowLayout(); fr.getContentPane().add(new JLabel(click and drag the mouse); tf=new JTextField(30); fr.getContentPane().add(tf); fr.addMouseListener(this); fr.addMouseMotionListener(this); fr.setSize(300,200); fr.setVisible(true); public static void main(
8、String args) TwoListener twolistener = new TwoListener(); ,public void mouseDragged(MouseEvent e) String s=Mouse dragging:X=+e.getX()+Y=+e.getY(); tf.setText(s); public void mouseMoved(MouseEvent e) String s=Mouse moved:X=+e.getX()+Y=+e.getY(); tf.setText(s); public void mouseClicked(MouseEvent e) S
9、tring s=Mouse clicked:X=+e.getX()+Y=+e.getY(); tf.setText(s); public void mouseEntered(MouseEvent e) String s=The mouse entered; tf.setText(s); public void mouseExited(MouseEvent e) public void mousePressed(MouseEvent e) public void mouseReleased(MouseEvent e) ,事件 MyFrame_this_windowAdapter(MyFrame adapte
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年太阳能电池生产专用设备项目建议书
- 2025年汽车车速传感器项目合作计划书
- 2025年应急救生系统项目建议书
- 贵州省黔东南苗族侗族自治州2024-2025学年高一上学期1月期末考试 语文 含解析
- 2025年新型分子筛系列产品项目建议书
- 客户服务层次化响应体系构建
- 娱乐行业演出安全协议书
- Rebaudioside-E-Standard-生命科学试剂-MCE
- 伊索寓言小动物的故事解读
- 监控采购安装合同
- 硫酸分公司30万吨硫磺制酸试车方案
- 高压氧科工作总结高压氧科个人年终总结.doc
- 电子电路基础习题解答
- 《政治学概论》教学大纲
- 食品生物化学习题谢达平(动态)
- 保安员工入职登记表
- 断路器控制回路超详细讲解
- 签证户口本完整翻译模板
- 睿达RDCAM激光雕刻切割软件V5.0操作说明书
- 变电设备运行与维护培训课件(共102页).ppt
- 机械设计基础平面连杆机构课件
评论
0/150
提交评论