基本信息
源码名称:java基于设计模式的绘图程序(源码)
源码大小:0.01M
文件格式:.zip
开发语言:Java
更新时间:2019-06-23
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
1.需求分析 该系统是一个画图程序,我们要用设计模式的思想来设计系统结构,然后实现基本图形的绘制功能。 1.1 设计模式要求 至少在其中运用 3 种模式,其中涉及到的模式有装饰模式、策略模式、桥梁模式三种。 1.2 画图基本要求 能实现基本图形的绘制功能 1.3 画图高级要求 实现图形的操作(如选取、移动、放大、缩小、改变颜色、改变线形等)和持久化



package jdgc;


import java.awt.BorderLayout;
import java.awt.Graphics;


import java.awt.Color;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;

import javax.swing.JPanel;

public class Main {
	
	static Color c;
	static int x = 0;
	static int y = 0;
	static String a;

	public static void main(String []args){
		final JFrame jf = new JFrame("绘图");
		jf.setSize(1000,700);
		jf.setLocation(500,300);
		//边界布局
		jf.setLayout(new BorderLayout() );
		
		final JPanel panel1= new JPanel();
		panel1.setSize(950,700);
		panel1.setLocation(50,50);
		panel1.setBackground(Color.white);
		//panel1.setLayout(null);
		
		
		final JPanel panel2= new JPanel();
		panel2.setSize(700,40);
		panel2.setLocation(0,0);
		panel2.setBackground(Color.gray);
		
		
	
		
		
		final JButton bj = new JButton("矩形");
		bj.setSize(100,35);
		bj.setLocation(0,0);
		final JButton by = new JButton("圆形");
		by.setSize(100,35);
		by.setLocation(100,0);
		final JButton bs = new JButton("三角形");
		bs.setSize(100,35);
		bs.setLocation(200,0);
		final JButton cl = new JButton("清屏");
		bs.setSize(100,35);
		bs.setLocation(300,0);
		final JButton co = new JButton("颜色");
		bs.setSize(100,35);
		bs.setLocation(400,0);
		
		
		panel2.add(bj);
		panel2.add(by);
		panel2.add(bs);
		panel2.add(cl);
		panel2.add(co);
		
		
		
		
		jf.add(panel1,BorderLayout.CENTER);
		
		jf.add(panel2,BorderLayout.NORTH);
		
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setVisible(true);//设置窗体可见
		
		
        bj.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub

				a ="1";
			

     	}
			
		});
        
        by.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub

				a ="2";
				

			}
		});

        bs.addActionListener(new ActionListener() {
	
        	@Override
        	public void actionPerformed(ActionEvent e) {
        		// TODO Auto-generated method stub

        		a ="3";
        		

			
				
	}
});
        
        cl.addActionListener(new ActionListener() {
        	
        	@Override
        	public void actionPerformed(ActionEvent e) {
        		// TODO Auto-generated method stub
        		
        		panel1.repaint();
	
	}
});
        
        co.addActionListener(new ActionListener() {
        	
        	@Override
        	public void actionPerformed(ActionEvent e) {
        		// TODO Auto-generated method stub

        		c = JColorChooser.showDialog(null, "Choose a Color", co.getForeground());
	
	}
});
        
        panel1.addMouseListener(new MouseAdapter(){
			public void mousePressed(MouseEvent e) {//鼠标按下
				x = e.getX();
				y = e.getY();
			}
			
			public void mouseReleased(MouseEvent e) {//鼠标释放

				Graphics g = panel1.getGraphics();//画笔
				drawProduct dp = drawFactory.create(a);
				dp.paint(g);
			
			}



        });
		
		
		

	}


}