- 浏览: 17157 次
- 性别:
最新评论
画板
- 博客分类:
- 入门
窗体类
监听器
package com032802; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JColorChooser; import javax.swing.JFrame; import javax.swing.JSlider; public class DrawBorder extends JFrame{ //定义主函数 public static void main(String[] args){ //实例化DrawBorder类的对象 DrawBorder db=new DrawBorder(); //调用initUI函数 db.initUI(); } //定义一个initUI函数 public void initUI(){ //设置属性值 this.setTitle(""); this.setSize(800, 900); this.setDefaultCloseOperation(3); this.setResizable(true); this.setLocationRelativeTo(null); this.setLayout(new FlowLayout()); //实例化按钮 JButton butLine=new JButton("Line"); JButton butRect=new JButton("Rect"); JButton butOval=new JButton("Oval"); JButton butColor=new JButton("Color"); JButton butOval0=new JButton("Oval0"); JButton butRect0=new JButton("Rect0"); JButton butSanJiao=new JButton("SanJiao"); JButton butRand=new JButton("Rand"); JButton butWall=new JButton("Wall"); JButton butRing=new JButton("Ring"); //将按钮添加到窗体上 this.add(butLine); this.add(butRect); this.add(butOval); this.add(butColor); this.add(butOval0); this.add(butRect0); this.add(butSanJiao); this.add(butRand); this.add(butWall); this.add(butRing); ActionListener a=new ActionListener(){ public void actionPerformed(ActionEvent e){ if(e.getActionCommand().equals("Color")){ color=JColorChooser.showDialog(null, "颜色的选择", Color.black); System.out.println("Color="+color); } else{ str=e.getActionCommand(); System.out.println("str="+str); } } }; //给按钮添加监听器 butLine.addActionListener(a); butRect.addActionListener(a); butOval.addActionListener(a); butColor.addActionListener(a); butOval0.addActionListener(a); butRect0.addActionListener(a); butSanJiao.addActionListener(a); butRand.addActionListener(a); butWall.addActionListener(a); butRing.addActionListener(a); this.setVisible(true); //取得画布 Graphics g=this.getGraphics(); DrawListener d=new DrawListener(g); this.addMouseListener(d); //实例化拉杆并设置拉杆属性 JSlider js=new JSlider(); js.setMaximum(300); js.setValue(10); //给拉杆添加监听器 MyChangeListener mcl=new MyChangeListener(js,this,g); js.addChangeListener(mcl); this.add(js); } public static Color color=Color.black; public static String str="Line"; }
监听器
package com032802; import com032802.DrawBorder; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Random; public class DrawListener implements MouseListener{ public int x1,x2,y1,y2,x0,y0,xp,yp; public double x3,x4,y3,y4; public int x,y; public static float a=1.7f,b=1.7f,c=0.06f,d=1.2f; public static float a1=1.4f,b1=1.56f,c1=1.4f,d1=-6.56f; //实例化随机数 Random rd=new Random(); Graphics g; public DrawListener(Graphics g){ this.g=g; } public void mousePressed(MouseEvent e) { x1=e.getX(); y1=e.getY(); } public void mouseReleased(MouseEvent e) { System.out.print("ssss"); x2=e.getX(); y2=e.getY(); g.setColor(DrawBorder.color); if(DrawBorder.str.equals("Rect0")){ this.DrawRect0(e); }else if(DrawBorder.str.equals("Line")){ g.drawLine(x1,y1,x2,y2); }else if(DrawBorder.str.equals("Rect")){ g.drawRect(x1, y1, Math.abs(x1-x2), Math.abs(y1-y2)); }else if(DrawBorder.str.equals("Oval")){ g.drawOval(x1, y1,Math.abs(x1-x2), Math.abs(y1-y2)); }else if(DrawBorder.str.equals("Oval0")){ this.DrawOval0(e); }else if(DrawBorder.str.equals("SanJiao")){ this.DrawSanJiao(e); }else if(DrawBorder.str.equals("Rand")){ this.DrawRand(e); }else if(DrawBorder.str.equals("Wall")){ this.DrawWall(e); }else if(DrawBorder.str.equals("Ring")){ this.DrawRing(e); } } public void DrawRect0(MouseEvent e){ for(int i=0;i<100;i++){ if(x1!=x2||y1!=y2){ g.drawRect(x1, y1,Math.abs(x1-x2),Math.abs(y1-y2)); x1=x1+2;y1=y1+2;x2=x2-2;y2=y2-2; } } } public void DrawOval0(MouseEvent e){ for(int i=0;i<50;i++){ g.drawOval(x1, y1,Math.abs(x1-x2), Math.abs(y1-y2)); x1=x1+2;y1=y1+2;x2=x2-2;y2=y2-2; } } public void DrawSanJiao(MouseEvent e){ for(int i=0;i<100;i++){ g.drawLine(x1, y1,x2,y1); x1--;y1=y1+2;x2++; } } public void DrawRand(MouseEvent e){ x0=rd.nextInt(1000); y0=rd.nextInt(1000); x1=rd.nextInt(1000); y1=rd.nextInt(1000); x2=rd.nextInt(1000); y2=rd.nextInt(1000); xp=rd.nextInt(1000); yp=rd.nextInt(1000); for(int i=0;i<10000;i++){ int r=rd.nextInt(3); switch(r){ case 0: {xp=(x0+xp)/2; yp=(y0+yp)/2; g.drawLine(xp, yp, xp, yp);break; } case 1: {xp=(x1+xp)/2; yp=(y1+yp)/2; g.drawLine(xp, yp, xp, yp);break; } case 2: {xp=(x2+xp)/2; yp=(y2+yp)/2; g.drawLine(xp, yp, xp, yp);break;} } } } public void DrawWall(MouseEvent e){ for(int i=0;i<1000000;i++){ x4=Math.sin(a*y3)+Math.cos(a*x3)*c; y4=Math.sin(b*x3)+Math.cos(b*y3)*d; x3=x4; y3=y4; x=(int)(x3*100)+500; y=(int)(y3*100)+500; g.drawLine(x, y, x, y); } } public void DrawRing(MouseEvent e){ for(int i=0;i<50000;i++){ x4=d1*Math.sin(a1*x3)-Math.sin(b1*y3); y4=c1*Math.cos(a1*x3)+Math.cos(b1*y3); x3=x4; y3=y4; x=(int)(x3*10)+500; y=(int)(y3*10)+500; g.drawLine(x, y, x, y); } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } }
拉杆 package com032802; import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JSlider; import javax.swing.event.ChangeEvent; public class MyChangeListener implements javax.swing.event.ChangeListener{ public JSlider js; public JFrame jf; public Graphics g; int x,y,x1=50,x2=500,y1=50,y2=500; //构造方法 public MyChangeListener(JSlider js,JFrame jf,Graphics g){ this.js=js; this.jf=jf; this.g=g; } public void stateChanged(ChangeEvent e) { js.getValue(); int w=jf.getWidth(); int h=jf.getHeight(); for(int i=0;i<255;i++){ Color c=new Color(0,i,i); g.setColor(c); g.fillOval(x1,y1,Math.abs(x1-x2),Math.abs(y2-y1)); x1++;y1++;x2--;y2--; } ImageIcon im=new ImageIcon("images/签名0.jpg"); Image ima=im.getImage(); g.drawImage(ima,w/4+300,h/4+100,null); } }
发表评论
-
数组变为链表
2013-04-19 00:28 2428数组实现链表 1 建立一个节点类LinkNode packa ... -
链表实现队列
2013-04-17 22:45 891用链表实现队列 1 建立链表节点类 public Link ... -
方形
2013-03-27 01:06 667package com032603; import ja ... -
画三角形
2013-03-27 01:05 641package com032602; import ja ... -
画圆
2013-03-27 01:02 715package com0326; import java ... -
图片集
2013-03-25 01:04 471使用画板实现如下图像 -
画图板
2013-03-25 01:01 617package com032401; 例子: import ... -
继承
2013-03-25 00:56 707继承 1 关键字:extenfs 2 格式:public cl ... -
类和对象
2013-03-25 00:52 6171 对象:客观存在的某一事物或物体 例如:某个人,一 ...
相关推荐
几何画板最强中文永久免费5.06版本安装包下载解压安装即可几何画板最强中文永久免费5.06版本安装包下载解压安装即可几何画板最强中文永久免费5.06版本安装包下载解压安装即可几何画板最强中文永久免费5.06版本安装包...
几何画板基础篇 基础篇之: 几何画板作图方法 1 利用基本工具作图----甘志高(laoshi_G)编写 2 用构造菜单作图---甘志高(laoshi_G)编写 1.1 几何画板的启动和绘图工具的使用 1.2 用绘图工具绘制简单的几何图形 1.3...
几何画板重要工具包,提供便捷的几何画板工具,随心所欲地创造几何图形。 工具包括:线工具、角工具、三角形、四边形、正多边形、圆工具、新新坐标系、迷你坐标系、经典坐标系、函数工具、箭头工具、圆锥曲线A、圆锥...
金排物理画板破解版是一款以Word为基础,方便物理教师进行物理教学的专业性工具,包括200多个图形和符号以及对这些图形进行处理的一套工具。金排物理画板内附多种物理素材,包括磁学、电学、光学、热学、力学等,可...
1、实现友好的Windows画板界面,包括Windows基本菜单、画图功能菜单和常用菜单的工具栏。 2、实现画不同颜色,不同宽度,不同线型的线段、椭圆和矩形。 3、实现自定义字体的大小颜色并且输出到画图板上。 4、实现画...
将几何画板转换成EXE文件,这样运行几何画板文件就不需要安装几何画板了
将电脑屏幕或一张图片当成画板的小工具,也可以截图和保存。功能说明:。1:可抓取屏幕或打开一个图片,F9抓取屏幕;。2:按住Shift键可画正方形,画线时可捕捉45度角和90度;。3:按住Ctrl键可从中心位置开始画;。...
画板的实现非常有趣,首先要新建一张HBITMAP来保存原来的绘制内容,然后需要创建一个可拉伸的输入框,供用户输入文字。必要时还得提供UnDo功能,供用户取消上一次绘制的功能。 利用业余时间,我制作了一个画板程序,...
火山安卓高级画板实现画板开发源码
python项目——超级画板.zip python项目——超级画板.zip python项目——超级画板.zip python项目——超级画板.zip python项目——超级画板.zip python项目——超级画板.zip python项目——超级画板.zip python项目...
1. 画板UI设计(总体布局) (1)创建窗体并设置相关属性; (2)给整个窗体添加一个中间容器用来覆盖整个窗体; (3)设置边框布局,因为整个画板大致为左边部分,中间部分,菜单栏三个部分,用边框布局比较合适; ...
易语言画板滚动条源码,画板滚动条,NewProc,置横向滚动条,置纵向滚动条,GetStockObject,SetCapture,ReleaseCapture,GetDC,CreateCompatibleBitmap,SelectObject,BitBlt,DeleteDC,CreateCompatibleDC,SetWindowLongA,...
Module Name: C++实现控制台版本的画板程序 Description: 本程序使用C++语言编写控制台程序,模仿Windows 下的【画板程序】,但是在DOS下只支持16色的颜色所以本程序 不见得很好,但是模仿了windows画板原理......
JAVA实现小画板课程设计 学习了《Java面向对象编程》的课程,为了更进一步的提高我们对Java的深入学习,进行了课程设计,我所选择课程设计是利用Java的GUI实现画图应用程度。其目的是通过本课程设计使我们能够较全面...
下载后把“按选中对象创建画板.jsx”文件复制到“\Adobe Illustrator XX\Presets(部分版本可能显示为预设)\zh_CN\脚本”文件夹中; 重开AI软件,然后在AI菜单“文件”——“脚本”下可以看见你刚才放进去的脚本...
画板是一个可以自已定制画板界面和图库并按分类进行作画的一个小程序,界面非常精美。其中PaintDlg.DLL封装了画板的主模块。Paint.Exe为执行调用画板的一个可执行文件示例(用于指定打开画板是在什么类型下,如卡通画...
几何画板自定义工具合集 将下载的工具文件夹放到几何画板安装目录下,打开几何画板软件,在自定义工具点击“选择工具文件夹”。在弹出的对话框中找到你放在安装目录下的工具文件夹,单击选中该文件,然后点击“选择...
ios画板源码ios画板源码ios画板源码ios画板源码ios画板源码
2023年最新的Sketchpad几何画板工具包,44个自定义工具文件夹,包含800多个小工具。包含使用示例。GSP软件工具包,包含GSP软件,一键打开使用,不用安装。
4.设置界面能够对画板的背景色进行设置 5.点击“开始绘画”按钮,进入画图板 6.画笔写字画画时,线条较为连续 7.画图板界面可以点击按钮返回到设置界面 8.从设置界面重新再次进入画图板后,能够保存之前的内容 9....