# (一)用户自定义成分 ### 1.绘制图形 Public voit piant(Ghraphics g){ g.drawLine等图形名称(坐标1234);g.file图形名(坐标123)} ### 2.设置字体-Font类 (1)定义font:Font myfont=new Font(“字体”,”样式”,字号); 例如:Font myfont=new Font(“宋体”,Font.BOLD,12); (2)引用定义的Font:类/容器/控件等.setFont(myfont); 例如:Graphics g=new Graphics();g.setFont(myfont); ### 3.设置颜色 Color co=new Color(R,G,B);三原色,类型是int或者float;对象:setColor(co); 此外还有: .setBackColor(Color co);getBackColor(Color co);setForeColor(Color co);getForeColor(Color co); ### 4.显示图片 二进制图像(跟图片不同,一般少用,最多调用一些系统内在的图像) Graphics g=new Grahphics();g.drawImage(笔刷类对象,x0,y0,x1,y1,对象(画纸)); ### 5.实现动画效果 原理跟flash动画一样,图片运动 ------------ # (二)java的标准组件与事件处理 1.java事件处理机制: 事件源+注册监听对象——触发事件actionevent—调用和传递参数——监听者实现接口; 2.GUI标准组件概述 使用控制组件一般的过程: (1)创建组件类的新对象,指定属性(外观大小)——对象实例化 (2)添加到相关的位置或者容器中 (3)注册给一个事件监听者,方便它对控件发生的事件做出响应 # 3.事件监听和接口 ------------ ## (1)ActionEvent动作事件 发起原因:单击双击选择菜单 文本的回车等 注册方法:事件源对象.addActionListener(监听者) 监听接口:ActionListener 处理方法:actionPerformed(ActionEvent e) ------------ ## (2)ItemEvent项目事件 发起原因:列表框改变、下拉选单选中、复选改变状态等 注册方法:事件源.addItemListener(监听者) 监听接口:ItemListener 处理方法:itemStateChanged(ItemEvent e) ------------ ## (3)MouseEvent 鼠标事件 引起原因:鼠标点击进入等等变化 注册方法:事件源.addMouseListener(监听者) 监听接口:MouseListener 处理方法:mouseClick/mouseEnter /mouseExit/mousePressed/mouseReleased(MouseEvent e) ------------ ## (4)MouseMotion 鼠标移动事件(鼠标移动) 引起原因:鼠标移动拖动 注册方法:事件源.MouseMotionListener(监听者) 监听接口:MouseMotionEvent 处理方法:mouseMove/mouseDragged(MouseEvent e) ------------ ## (5)KeyEvent键盘操作事件 引起原因:键盘操作 注册方法:事件源.addKeyListener(监听者) 监听接口:KeyListener 处理方法:keyPress/KeyRelease/KeyTyped(KeyEvent e) ------------ ## (6)FocusEvent 焦点事件 产生原因:组件焦点获取和失去 注册方法:事件源.addFocusListener(监听者) 监听接口:FocusListener 处理方法:focusGained/focusLost(FocusEvent e) ------------ ## (7)AdjustmentEvent 调整事件 产生原因:滚动条变化 注册方法:事件源.addAdjustmentListener(监听者) 监听接口:AdjustmentListener 处理方法:adjustmentValueChanged(AdjustmentEvent e) ------------ ## (8)TextEvent 文本事件 产生原因:文本内容变化 注册方法:事件源.addTextChangedListener(监听者) 监听接口:TextListener 处理方法:textValueChanged(TextEvent e) ------------ ## (9)ComponentEvent 组件事件 产生原因:组建移动,改变大小,可见性等 注册方法:事件源.addComponentListener(监听者) 监听接口:ComponentListener 处理方法:componentHidden/moved/Resized/Shown(ComponentEvent e) ------------ ## (10)WindowEvent 窗口事件 产生原因:窗体变化 注册方法:事件源.addWindowsListener(监听者) 监听接口:WindowListener 处理方法:windowClosed/Opened/Closing/Activated/Deactivated/Iconfied(最小化)/ windowDeiconfied(最大化)(WindowEvent e) ------------ ## (11)ContainerEvent 容器事件 产生原因:容器增加或移走 注册方法:事件源.addContainerListener(监控者) 监听接口:ContainerListener 处理方法:componentAdd/Removed(ComtainerEvent e) Last modification:March 4, 2019 © Allow specification reprint Support Appreciate the author AliPayWeChat Like If you think my article is useful to you, please feel free to appreciate