简化画板资料_第1页
简化画板资料_第2页
简化画板资料_第3页
全文预览已结束

下载本文档

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

文档简介

import java awt import java awt event import javax swing import java io public class huahua extends JFrame DrawPanel drawingArea int index 0 drewings itemList new drewings 5000 Container c getContentPane public huahua super 简单画板 drawingArea new DrawPanel c add drawingArea BorderLayout CENTER itemList index new Penci setSize 500 500 setVisible true show public static void main String Strgs new huahua class mousea extends MouseAdapter public void mousePressed MouseEvent e itemList index x1 itemList index x2 e getX itemList index y1 itemList index y2 e getY index itemList index new Penci public void mouseReleased MouseEvent e itemList index x1 e getX itemList index y1 e getY 重新获取 x1y1 的值 虽然移动的时候 x1y1 在变但那时移动监听的不是 释放监听的 如果不重新获取坐标将变成默认的 0 0 itemList index x2 e getX itemList index y2 e getY repaint index itemList index new Penci public void mouseEntered MouseEvent e public void mouseExited MouseEvent e class mouseb extends MouseMotionAdapter public void mouseDragged MouseEvent e itemList index 1 x1 itemList index x2 itemList index x1 e getX itemList index 1 y1 itemList index y2 itemList index y1 e getY 按住移动是获取了 x1y1 的坐标但这坐标不会赋值给释放 动作不同不 会相互赋值 index itemList index new Penci repaint public void mouseMoved MouseEvent e class DrawPanel extends JPanel public DrawPanel setBackground Color white addMouseListener new mousea addMouseMotionListener new mouseb Override public void paintComponent Graphics g super paintComponent g Graphics2D g2d Graphics2D g 定义画笔 int j 0 while j index drew g2d itemList j j void drew Graphics2D g2d drewings i i drew g2d 将画笔传入到各个子类中 用来完成各自的绘图 class drewings implements Serializable int x1 y1 x2 y2 void drew Graphics2D g2d class Penci

温馨提示

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

评论

0/150

提交评论