zoukankan      html  css  js  c++  java
  • 作业四

    简单的画图软件

     

     

    主要代码

    package com.listener;
    
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Paint;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.util.ArrayList;
    import java.util.concurrent.Callable;
    import java.util.concurrent.FutureTask;
    
    import javax.swing.JButton;
    import javax.swing.JPanel;
    
    import com.board.Board;
    
    public class LineListener implements MouseListener,ActionListener,MouseMotionListener{
    	Board board;
    	JPanel zone;
    	Graphics g;
    	Graphics2D g2;
    	Paint paint;
    	public final int LINE=1;
    	public final int RECT=2;
    	public final int CIRCLE=3;
    	public int fig=0;
    	ArrayList listx=new ArrayList();
    	ArrayList listy=new ArrayList();
    	int x1=0;
    	int x2=0;
    	int y1=0;
    	int y2=0;
    	
    	
    	@Override
    	public void mouseClicked(MouseEvent e) {
    		// TODO 自动生成的方法存根
    		
    		switch(fig){
    			case LINE:drawline(e) ;
                case RECT: drawrect(e);
    			case CIRCLE: drawcircle(e);
    
    		}
    		
    		
    	}
    	/*
    	 * draw circle
    	 */
    	public void drawcircle(MouseEvent e){
    		getzone(e);
    		if(g==null){
    			g=zone.getGraphics();
    		}
    		g.drawOval(e.getX(), e.getY(), 40, 40);
    		
    		zone.paintComponents(g);
    		
    	}
    
    	/*
    	 * draw rect
    	 */
    	public void drawrect(MouseEvent e){
    		getzone(e);
    		if(g==null){
    			g=zone.getGraphics();
    		}
    		g.drawRect(e.getX(), e.getY(), 40, 40);
    		zone.paintComponents(g);
    		
    	}
    
    	/*
    	 * draw line
    	 */
    	public void drawline(MouseEvent e){
    		getzone(e);
    		if(g==null){
    			g=zone.getGraphics();
    		}
    		
    		if(x1==0&&y1==0){
    			//g.drawLine(x1, y1, x1+20, y1+10);
    			x2=e.getX();
    			y2=e.getY();
    			g.drawLine(x2, y2, x2, y2);
    			listx.add(x2);
    			listy.add(y2);
    			x1=x2;
    			y1=y2;
    		}
    		else{
    			x2=e.getX();
    			y2=e.getY();
    			g.drawLine(x1, y1, x2, y2);
    			listx.add(x2);
    			listy.add(y2);
    			x1=x2;
    			y1=y2;
    		}
    		
    		zone.paintComponents(g);//show line
    		
    		System.out.println(x1+"/n"+y1);
    	}
    	
    	
    	/*
    	 * get zone to draw
    	 * 
    	 */
    	public void getzone(MouseEvent e){
    		if(zone==null){
    			zone=(JPanel) e.getSource();
    		}
    		
    	}
    	@Override
    	public void mouseEntered(MouseEvent arg0) {
    		// TODO 自动生成的方法存根
    	}
    
    	@Override
    	public void mouseExited(MouseEvent arg0) {
    		// TODO 自动生成的方法存根
    	}
    
    	@Override
    	public void mousePressed(MouseEvent arg0) {
    		// TODO 自动生成的方法存根
    	}
    
    	@Override
    	public void mouseReleased(MouseEvent arg0) {
    		// TODO 自动生成的方法存根
    	}
    
    	@Override
    	public void actionPerformed(ActionEvent e) {
    		// TODO 自动生成的方法存根
    		JButton but=(JButton) e.getSource();
    		
    		if(but.getText()=="线    "){
    			fig=LINE;
    			
    		}
    		else if(but.getText()=="矩形"){
    			fig=RECT;
    			
    		}
    		else if(but.getText()=="圆形"){
    			fig=CIRCLE;
    			
    		}
    	}
    	@Override
    	public void mouseDragged(MouseEvent e) {
    		// TODO 自动生成的方法存根
    		
    		drawline(e);
    		
    	}
    	
    	@Override
    	public void mouseMoved(MouseEvent arg0) {
    		// TODO 自动生成的方法存根
    
    	}
    	
    	
    }
    

      

    心得

    1在团队合作中要注意交流,在此次合作总由于没有很好的交流,导致花费时间较多

    2由于能力有限,做的不很精美

    合照

  • 相关阅读:
    Python pyspider 安装与开发
    Shell curl 和 wget 使用代理IP
    米扑代理示例(mimvp-proxy-demo)
    图片加载失败如何替换成默认图片
    Node-mongodb链接数据库函数的封装
    移动端拼图效果实现
    JS调用百度地图API获取地理位置
    The Begin
    Matlab(Client)和Python(Server)进行TCP通信
    ubuntu如何有效扩容根目录的记录(实践有效ubuntu20.0版本)
  • 原文地址:https://www.cnblogs.com/l1019/p/5905656.html
Copyright © 2011-2022 走看看