⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decorator.java

📁 java实现pplive
💻 JAVA
字号:
package com.decorators;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;

import com.moveShape.MyObserver;
import com.moveShape.Shape;

public class Decorator implements Shape
{
	 String name;
	 Shape shape;
	 Color color;
	 String colorName;
	 Point ulPoint,lrPoint;
	 boolean state;
	 Point mouseSource;
	
	public Decorator(Shape shape)
	{
		this.shape=shape;
		this.color=Color.red;
		this.colorName="red";
		this.ulPoint=shape.getULpoint();
		this.lrPoint=shape.getLRpoint();
		this.state=false;
		
	}
	
	
	public void changeColor(Color color, String colorName)
	{
		// TODO Auto-generated method stub
		this.color=color;
		this.colorName=colorName;
		shape.changeColor(color, colorName);
		
	}

	public void contain(Shape shape)
	{
		// TODO Auto-generated method stub
		shape.contain(shape);
		
	}

	public void deleteObserver(MyObserver observer)
	{
		// TODO Auto-generated method stub
		shape.deleteObserver(observer);
		
	}

	public void draw(Graphics g)
	{
		// TODO Auto-generated method stub
		
		
	}

	public String getDescrption()
	{
		// TODO Auto-generated method stub
		return (" "+name+" "+shape.getDescrption());
	}

	public boolean isInside(Point p)
	{
		// TODO Auto-generated method stub
		if(shape.isInside(p))
		{
			this.state=true;
			this.mouseSource=p;
			
		}
		return state;
	}

	public void move(Point mouseDestination)
	{
		// TODO Auto-generated method stub
		if(state==true)
		{
			Point destination=new Point();
			
			destination.x=ulPoint.x+(mouseDestination.x-mouseSource.x);
			destination.y=lrPoint.y+(mouseDestination.y-mouseSource.y);
			
			this.ulPoint=destination;
			
			this.mouseSource=mouseDestination;
			
		}	
		shape.move(mouseDestination);
	}

	public ArrayList<Shape> out()
	{
		// TODO Auto-generated method stub
		return null;
	}

	public void registerObserver(MyObserver observer)
	{
		// TODO Auto-generated method stub
		shape.registerObserver(observer);
	}

	public void save(String filename, int num)
	{
		// TODO Auto-generated method stub
		
		
	}

	public void setColor(Color color, String colorName)
	{
		// TODO Auto-generated method stub
		this.color=color;
		this.colorName=colorName;
	}

	public void setState(boolean state)
	{
		// TODO Auto-generated method stub
		this.state=state;
		shape.setState(state);
	}


	public Point getLRpoint()
	{
		// TODO Auto-generated method stub
		return lrPoint;
		
	}


	public Point getULpoint()
	{
		// TODO Auto-generated method stub
		return ulPoint;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -