当前位置: 首页 > news >正文

百度一对一解答长沙seo优化推广

百度一对一解答,长沙seo优化推广,工程设计东莞网站建设技术支持,h5网站建站思路#xff1a; ①画图板的界面 ②创建监听器类 ③给按钮加上鼠标监听 ③画图版的重绘 第一部分#xff1a;界面类 ①画图板的界面 ③给按钮加上鼠标监听 public class SampleDraw extends JFrame {public static void main(String[] args) {SampleDraw sam new Sam…思路 ①画图板的界面 ②创建监听器类 ③给按钮加上鼠标监听 ③画图版的重绘 第一部分界面类 ①画图板的界面 ③给按钮加上鼠标监听 public class SampleDraw extends JFrame {public static void main(String[] args) {SampleDraw sam new SampleDraw();//创建该类对象sam.showUI();//调用showUI方法}public void showUI() {this.setSize(800, 600);//设置尺寸this.setTitle(画板v1.0);//设置标题this.setLocationRelativeTo(null);//设置居中this.setDefaultCloseOperation(3);//设置关闭进程FlowLayout flow new FlowLayout();//布局方式为流式布局this.setLayout(flow);Color[] color { Color.GREEN, Color.RED, Color.BLUE, Color.YELLOW };//创建一个数组保存颜色DrawListener drawListener new DrawListener();//新建监听器对象for (int i 0; i color.length; i) {//利用循环将颜色依次将赋给按钮的背景色JButton jbu new JButton();jbu.setPreferredSize(new Dimension(30, 30));//设置按钮尺寸jbu.setBackground(color[i]);//设置按钮的背景色this.add(jbu);//把按钮加给窗体jbu.addActionListener(drawListener);//给按钮添加监听器}String[] name { 直线, 三角形, 正方形,矩形, 椭圆,棱形, 五边形, 图片1, 图片2, 画笔, 特殊三角形, 多边形 };创建一个数组保存按钮名称for (int i 0; i name.length; i) {//利用循环将名字赋给按钮JButton jbu1 new JButton(name[i]);//创建按钮对象this.add(jbu1);//把按钮对象加给窗体jbu1.addActionListener(drawListener);//给按钮添加监听器}this.setVisible(true); //设置窗体可见Graphics g this.getGraphics();//创建画笔this.addMouseListener(drawListener);//添加鼠标监听器this.addMouseMotionListener(drawListener);//添加鼠标拖动监听器drawListener.setGr(g);//调用监听器的set方法drawListener.setShape(listshape);//调用监听器的setShape方法} } 第二部分监听器类 ②创建监听器 该类应该继承MouseListener, ActionListener, MouseMotionListener的接口 public class DrawListener implements MouseListener, ActionListener, MouseMotionListener {private Graphics gr;//声明对象private Color color;private int flag 1;private String name;private int x1, y1, x2, y2, x3, y3,x4,y4;private ImageIcon icon new ImageIcon(C:\\Users\\Administrator\\Pictures\\lu.jpg);//添加图片。注意路径为绝对路径单斜杠变成双斜杠加文件名和后缀格式private ImageIcon icon2 new ImageIcon(C:\\Users\\Administrator\\Pictures\\hua.jpg);private ArrayListShape listshape;public void setGr(Graphics g) {//传画笔gr g;}public void setShape(ArrayListShape listshape) {//传数组this.listshape listshape;}public void actionPerformed(ActionEvent e) {//监听方法if (.equals(e.getActionCommand())) {//如果按钮的文本内容为JButton jbu (JButton) e.getSource();color jbu.getBackground();//获取按钮的背景色gr.setColor(color);} else {//按钮文本内容不为空name e.getActionCommand();//将按钮的文本内容赋给name}}public void mouseDragged(MouseEvent e) {x3 e.getX();//x3 y3 为鼠标按压拖动时的坐标y3 e.getY();if (画笔.equals(name)) {//如果点击是“画笔”按钮gr.drawLine(x1, y1, x3, y3);//画线x1 x3;y1 y3; // 更新x1,y1的值把每一个点依次相连。}}public void mouseMoved(MouseEvent e) {}public void mouseClicked(MouseEvent e) {x4 e.getX();//将鼠标点击时的坐标赋给x4,y4y4 e.getY();if (特殊三角形.equals(name) flag 2) {//此时flag为2时才能将点击的点和直线的两端链接起来gr.drawLine(x1, y1, x4, y4);//画线gr.drawLine(x2, y2, x4, y4);flag 1;//画完线后将flag的值赋为1这样能接着画第二个三角形}if (多边形.equals(name) flag 2) {gr.drawLine(x2, y2, x4, y4);x2 x4;y2 y4;if (e.getClickCount() 2) {//如果为双击gr.drawLine(x1, y1, x4, y4);flag 1;}}}public void mousePressed(MouseEvent e) {if (flag 1) {x1 e.getX();y1 e.getY();}}public void mouseReleased(MouseEvent e) {if (flag 1) {x2 e.getX();y2 e.getY();}if (直线.equals(name)) {gr.drawLine(x1, y1, x2, y2);}if (矩形.equals(name)) {gr.drawRect(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2), Math.abs(y1 - y2));}if (椭圆.equals(name)) {gr.drawOval(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2), Math.abs(y1 - y2));}if (三角形.equals(name)) {int[] xPoints new int[] { x1, Math.abs((x1 x2) / 2), x2 };int[] yPoints new int[] { y2, y1, y2 };int nPoints 3;gr.drawPolygon(xPoints, yPoints, nPoints);}if (图片1.equals(name)) {gr.drawImage(icon.getImage(), Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2), Math.abs(y1 - y2),null);}if (图片2.equals(name)) {gr.drawImage(icon2.getImage(), Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2), Math.abs(y1 - y2),null);}if (正方形.equals(name)) {gr.drawRect(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2), Math.abs(x1 - x2));}if (棱形.equals(name)) {int[] xPoints new int[] { (x1 x2) / 2, x2, (x1 x2) / 2, x1 };int[] yPoints new int[] { y2, (y1 y2) / 2, y1, (y1 y2) / 2 };int nPoints 4;gr.drawPolygon(xPoints, yPoints, nPoints);}if (五边形.equals(name)) {int[] xPoints new int[] { (x1 x2) / 2, x2, x2 - (x2 - x1) / 4, x1 (x2 - x1) / 4, x1 };int[] yPoints new int[] { y1, (y1 y2) / 2, y2, y2, (y1 y2) / 2 };int nPoints 5;gr.drawPolygon(xPoints, yPoints, nPoints);}if (特殊三角形.equals(name) flag 1) {gr.drawLine(x1, y1, x2, y2);flag;}if (多边形.equals(name) flag 1) {gr.drawLine(x1, y1, x2, y2);flag;}}public void mouseEntered(MouseEvent e) {}public void mouseExited(MouseEvent e) {} } 现在就实现了简单的画图版了但是会有一个问题当我们改变窗体的大小或者最小化窗体再打开来会发现之前画的图都不见了。这是因为当窗体发生改变时程序会重新从内存中获取更新后的数据绘制。我们没有将画过的形状存放到内存中当窗体发生重绘的时候就不会绘制了 第三步画图板的重绘 定义一个Shape类。 其中定义一个队列用于存放图形对象。队列的大小随对象的增加而增加 public class Shape {private String name;private Color color; private int x1, x2, y1, y2 ;private ImageIcon icon new ImageIcon(C:\\Users\\Administrator\\Pictures\\lu.jpg);private ImageIcon icon2 new ImageIcon(C:\\Users\\Administrator\\Pictures\\hua.jpg);public void setShape(int x1, int y1, int x2, int y2, String name, Color color) {this.x1 x1;this.x2 x2;this.y1 y1;this.y2 y2;this.name name;this.color color;}public void drawShape(Graphics g) {switch (name) {case 直线:g.setColor(color);g.drawLine(x1, y1, x2, y2);break;case 矩形:g.setColor(color);g.drawRect(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2), Math.abs(y1 - y2));break;case 椭圆:g.setColor(color);g.drawOval(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2), Math.abs(y1 - y2));break;case 三角形:g.setColor(color);int[] xPoints new int[] { x1, Math.abs((x1 x2) / 2), x2 };int[] yPoints new int[] { y2, y1, y2 };int nPoints 3;g.drawPolygon(xPoints, yPoints, nPoints);break;case 画笔:g.setColor(color);g.drawLine(x1, y1, x2, y2);break;case 正方形:g.setColor(color);g.drawRect(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2), Math.abs(x1 - x2));break;case 五边形:g.setColor(color);int[] xPoints1 new int[] { (x1 x2) / 2, x2, x2 - (x2 - x1) / 4, x1 (x2 - x1) / 4, x1 };int[] yPoints1 new int[] { y1, (y1 y2) / 2, y2, y2, (y1 y2) / 2 };int nPoints1 5;g.drawPolygon(xPoints1, yPoints1, nPoints1);break;case 棱形:g.setColor(color);int[] xPoints2 new int[] { (x1 x2) / 2, x2, (x1 x2) / 2, x1 };int[] yPoints2 new int[] { y2, (y1 y2) / 2, y1, (y1 y2) / 2 };int nPoints2 4;g.drawPolygon(xPoints2, yPoints2, nPoints2);break;case 特殊三角形:g.setColor(color);g.drawLine(x1, y1, x2, y2);break;case 多边形:g.setColor(color);g.drawLine(x1, y1, x2, y2);break;case图片1:g.setColor(color);g.drawImage(icon.getImage(), x1,y1,x2,y2,null);break;case图片2:g.setColor(color);g.drawImage(icon2.getImage(), x1,y1,x2,y2,null);break;}} } 再在监听器类中画一个图形就将图形存入Shape类中的队列中去。例如 if (直线.equals(name)) {gr.drawLine(x1, y1, x2, y2);Shape shape new Shape();shape.setShape(x1, y1, x2, y2, name, color);listshape.add(shape) ;} 最后在主界面的类中去定义重绘的方法和调用。在重绘方法中将队列中的对象取出来调用画的方法 public void paint(Graphics g) {//重绘方法super.paint(g);//进行重绘for (int i 0; i listshape.size(); i) {Shape shape listshape.get(i);//依次取出对象if (shape ! null) {shape.drawShape(g);//调用对象的画的方法} else {break;}}} 图形的重绘就到这里啦
http://www.hkea.cn/news/14420727/

相关文章:

  • 地图网站怎么做的中国互联网网站性能
  • 唐山网站建设怎么样wordpress大图模板
  • 易联网站制作设计制作公司网站
  • 人力资源网站怎么建设营销型网站的缺点
  • 网教网站源码网站做多久
  • 公司网站怎么做关键字wordpress 标签seo插件
  • 江苏平台网站建设价位成都市建设领域网站咨询电话
  • 北京 建公司网站要多少钱纸箱 东莞网站建设
  • 最漂亮网站电商网站开发平台一
  • 企业网站托管收费标准深信服对单一网站做限速
  • 专门做视频的网站有哪些不写代码门户网站建设
  • 现在还有没有做任务的网站wordpress 亲子主题
  • 河南网站推广夜间直播平台哪个好用
  • 网站关键词的分类搭建网站的六个基本步骤流程
  • php网站的优点交互设计软件有哪些
  • pc 手机网站 微站淘宝推广平台有哪些
  • 怎么建公司免费网站企业网站建立意义何在
  • 网站建立失败的原因是陕西建设厅执业资格注册中心网站
  • 海淀网站制作举例说明
  • 政元软件做网站神马seo服务
  • 赤峰做网站的网络公司网页设计列表
  • 潍坊网站制作保定公司电话wordpress页面文章区别
  • 深圳外贸公司网站wordpress 最快的版本
  • 网站建设模块分析wordpress 插件 注入
  • 怎么做网站营销策划网站建设合作合同
  • 企业网站的形式有哪些分销系统开发多少费用
  • 网站权重转移做排名电商类网站模板
  • 河北精品网站建设flash html网站模板
  • 转业做网站的工具网站开发技术支持与保障
  • 房山富阳网站建设凡客优品家居