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由于能力有限,做的不很精美

    合照

  • 相关阅读:
    一个帖子掌握android所有控件、ProgressBar 、Android 动画效果、SQLite、四大组件、Android多媒体(转
    Android开发交流群
    我的程序里 《我的歌声里》程序员版
    《老罗Android开发视频教程安卓巴士》(Android 开发)
    #百度360大战# 我为什么要支持360
    安卓巴士移动开发者周刊第九期
    水杯题的非常好的解释
    [LeetCode] Jump Game
    [LeetCode] Longest Common Prefix
    [CareerCup][Google Interview] 寻找动态的中位数
  • 原文地址:https://www.cnblogs.com/l1019/p/5905656.html
Copyright © 2011-2022 走看看