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

📄 mainpane.java

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

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class MainPane extends JPanel implements ActionListener
{
	private Pane paintPane;
	private OpenWorks works;
	private JButton save,open,divide,unite;
	private boolean isDivide;
	public MainPane()
	{
		paintPane=new Pane();
		save=new JButton("save");
		open=new JButton("open");
		divide=new JButton("divide");
		unite=new JButton("unite");
		
		isDivide=true;
		save.addActionListener(this);
		open.addActionListener(this);
		divide.addActionListener(this);
		unite.addActionListener(this);
		
		JPanel bottom = new JPanel();
		bottom.setLayout(new GridLayout(1,4));
		bottom.add(save);
		bottom.add(open);
		bottom.add(divide);
		bottom.add(unite);
		
		//add button
		this.setLayout(new BorderLayout());
		this.add(paintPane,BorderLayout.CENTER);
		//this.add(bottom,BorderLayout.SOUTH);
	}
	public void actionPerformed(ActionEvent com)
	{
		if(com.getSource()==save)
		{
			paintPane.save("./save.config");
		}
		else if(com.getSource()==open)
		{
			this.remove(paintPane);
			this.repaint();
			
			works=new OpenWorks("./save.config");
			Shape[] shape=works.showWork();
			
			int i=0;
			paintPane.moveAll();
			for(Shape singleShape:shape)
			{
				if(singleShape!=null)
				{
					paintPane.addShape(singleShape);					
				}
			}
			this.add(paintPane);
			JOptionPane.showMessageDialog(null,"Your work has been opened!^_^","message",JOptionPane.INFORMATION_MESSAGE);
		}
		else if(com.getSource()==unite)
		{
			if(isDivide)
			{
				
				paintPane.unite();
				isDivide=false;
				JOptionPane.showMessageDialog(null,"The shapes has been united!^_^","message",JOptionPane.INFORMATION_MESSAGE);
			}
		}
		else if(com.getSource()==divide)
		{
			if(!isDivide)
			{
				paintPane.divide();
				isDivide=true;
				JOptionPane.showMessageDialog(null,"The shapes has been divided!^_^","message",JOptionPane.INFORMATION_MESSAGE);
			}
		}
		
	}
	
}

⌨️ 快捷键说明

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