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

📄 drawpanel.java

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

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import java.util.ArrayList;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

public class DrawPanel extends JPanel 
{

	//shapes that the panel draws
	private ArrayList<Shape> shapes;
	private boolean[] shapesState;
	private Shape container;
	
	
	
	
	
	
	
	public DrawPanel()
	{
		container=new Container();
		shapes=new ArrayList<Shape>();
		this.setBorder(new LineBorder(Color.blue));
		//this.addMouseListener(new MyMouseListener(this));
		//this.addMouseMotionListener(new MyMouseListener(this));
	}
	
	
	
	public void addShape(Shape shape)
	{
		
		shapes.add(shape);
	}
	
	
	public void moveAll()
	{
		shapes.clear();
	}
	
	/**
	 * get the shapes
	 */
	
	public ArrayList<Shape> getShapes()
	{
		return shapes;
	}
	
	
	
	
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		for(Shape shape:shapes)
		{
			shape.draw(g);
		}
	}
	
	
	public void save(String fileName)
	{
		
		File file=new File(fileName);
		boolean del=file.delete();
		if(!del)
		{
			return;
		}
		int num=shapes.size();
		saveNum(fileName,num);
		for(int i=0;i<num;i++)
		{
			(shapes.get(i)).save(fileName,i);
		}
		JOptionPane.showMessageDialog(null, "Your work has been saved!^_^", "message", JOptionPane.INFORMATION_MESSAGE);
	}
	
	private void saveNum(String fileName,int num)
	{
		try
		{
			FileOutputStream out=new FileOutputStream(new File(fileName),true);
			String count="num = "+num+"\n";
			out.write(count.getBytes());
			out.flush();
			out.close();
		}catch(IOException e)
		{
			
		}
		
		
	}
	
	
	public void unite()
	{
		
		for(Shape shape:shapes)
		{
			container.contain(shape);
		}
		shapes.clear();
		shapes.add(container);
	}
	
	
	public void divide()
	{
		shapes.clear();
		ArrayList<Shape> temp=container.out();
		
		for(int i=0;i<temp.size();i++)
		{
			shapes.add(temp.get(i));
		}
		
		
		for(Shape shape:shapes)
		{
			shape.setState(false);
		}
	}
}

⌨️ 快捷键说明

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