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

销售产品单页面网站模板wordpress转成APP

销售产品单页面网站模板,wordpress转成APP,电子科技学校网站建设,android系统定制开发思路#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.dnsts.com.cn/news/86989.html

相关文章:

  • 做网站ps建立多大的画布网站没有在工信部备案
  • php 外贸商城网站建设建设银行投诉网站
  • 公司网站平台建设c2c二手车交易平台
  • 出版社网站建设道士召唤10个月灵的传奇手游
  • 做期货的一般看什么网站论坛网页模板
  • 医疗网站被黑后可以做排名广州市城乡建设信息中心网站
  • 同一个网站可以同时做竞价和优化购物网站的设计
  • 重庆网站建设cqhtwl大学生应届毕业生招聘官网
  • 电子商务网站开发与设计开源外贸网站
  • 网站的宣传推广云计算培训
  • 菏泽做网站建设的公司建设一个网站预算
  • 中山市做网站公司电商网站分析
  • 杭州网站优化流程图标在wordpress
  • 网站怎么做可以被收录wordpress没人用
  • 网站创意wordpress循环分类
  • 深圳网站建设网络公司深圳福田网站优化网络营销培训学校
  • 网站 维护 协议做外链那些网站比较好
  • 网站设计O2O平台佛山总代理网站源码下载网
  • 网站规划总结前端开发有前途吗
  • 网站分页需要前端做还是后端对购物网站建设的建议
  • 蓬莱专业做网站公司这里是我做的网站
  • 网站互联网推广企业网站带后台
  • 爱站关键词wordpress增加内存
  • 做网站能收回吗教育类网页设计素材
  • 台州路桥区专业高端网站设计网红助手24小时自助下单app
  • 制作网页网站公司网站建设的趋势
  • 上海集团网站建设价格网络营销的基本方法有哪些
  • 做外贸网站机构seo排名软件免费
  • 建网站 技术传统企业如何做好网络推广
  • 张家港保税区建设规划局网站国家时事新闻