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

📄 figurepanel.java

📁 基于java Swing的一款简单的2D图形绘制软件程序
💻 JAVA
字号:
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JPanel;

/**
 * 
 */

/**
 * @author squirrel
 *
 */
public class FigurePanel extends JPanel{

	private JPanel buttonPanel;
	private EasyColorPanel easyColorPanel;
	
	private Button curveButton;
	private Button lineButton;
	private Button ellipseButton;
	private Button rectangleButton;
	
	private ScreenCanvas screenPanelHand;
	
	public FigurePanel()
	{
		this.setLayout(new BorderLayout());
		
		curveButton = new Button("曲线");
		lineButton = new Button("直线");
		ellipseButton = new Button("椭圆");
		rectangleButton = new Button("方形");
		
		curveButton.setBackground(Color.WHITE);
		lineButton.setBackground(Color.WHITE);
		ellipseButton.setBackground(Color.WHITE);
		rectangleButton.setBackground(Color.WHITE);
		
		buttonPanel = new JPanel();
		buttonPanel.setLayout(new GridLayout(4,1,1,1));
		buttonPanel.add(lineButton);
		buttonPanel.add(curveButton);
		buttonPanel.add(ellipseButton);
		buttonPanel.add(rectangleButton);
		
		easyColorPanel = new EasyColorPanel();
		
		lineButton.addActionListener(new ButtonActionListener());
		curveButton.addActionListener(new ButtonActionListener());
		ellipseButton.addActionListener(new ButtonActionListener());
		rectangleButton.addActionListener(new ButtonActionListener());
		
		buttonPanel.setSize(new Dimension(100,250));
		easyColorPanel.setSize(new Dimension(100,350));
		buttonPanel.setBorder(BorderFactory.createTitledBorder("绘图形状"));
		easyColorPanel.setBorder(BorderFactory.createTitledBorder("颜色盒"));
		this.setLayout(new GridLayout(2,1,1,1));
		this.add(buttonPanel);
		this.add(easyColorPanel);
		
		this.setBackground(Color.LIGHT_GRAY);
	}

	public JPanel getButtonPanel() {
		return buttonPanel;
	}

	public void setButtonPanel(JPanel buttonPanel) {
		this.buttonPanel = buttonPanel;
	}

	public Button getEllipseButton() {
		return ellipseButton;
	}

	public void setEllipseButton(Button ellipseButton) {
		this.ellipseButton = ellipseButton;
	}

	public Button getLineButton() {
		return lineButton;
	}

	public void setLineButton(Button lineButton) {
		this.lineButton = lineButton;
	}

	public Button getRectangleButton() {
		return rectangleButton;
	}

	public void setRectangleButton(Button rectangleButton) {
		this.rectangleButton = rectangleButton;
	}
	
	public void setScreenPaneHand(ScreenCanvas panel)
	{
		this.screenPanelHand = panel;
		this.easyColorPanel.setScreenPanel(this.screenPanelHand);
		
	}
	
	
		private class ButtonActionListener implements ActionListener {

		/* (non-Javadoc)
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		public void actionPerformed(ActionEvent e) {
			Object source = e.getSource();
		    
			if(source.equals(curveButton))
			{
				lineButton.setBackground(Color.WHITE);
				curveButton.setBackground(Color.LIGHT_GRAY);
				ellipseButton.setBackground(Color.WHITE);
				rectangleButton.setBackground(Color.WHITE);
				
				screenPanelHand.setDrawShapeType(0);
			}
			else if(source.equals(lineButton))
			{
				lineButton.setBackground(Color.LIGHT_GRAY);
				curveButton.setBackground(Color.WHITE);
				ellipseButton.setBackground(Color.WHITE);
				rectangleButton.setBackground(Color.WHITE);
				
				screenPanelHand.setDrawShapeType(1);
			}
			else if(source.equals(ellipseButton))
			{
				lineButton.setBackground(Color.WHITE);
				curveButton.setBackground(Color.WHITE);
				ellipseButton.setBackground(Color.LIGHT_GRAY);
				rectangleButton.setBackground(Color.WHITE);
				
				screenPanelHand.setDrawShapeType(2);
			}
			else if(source.equals(rectangleButton))
			{
				lineButton.setBackground(Color.WHITE);
				curveButton.setBackground(Color.WHITE);
				rectangleButton.setBackground(Color.LIGHT_GRAY);
				
				screenPanelHand.setDrawShapeType(3);
			}
		}

	}


		public EasyColorPanel getEasyColorPanel() {
			return easyColorPanel;
		}

		public void setEasyColorPanel(EasyColorPanel easyColorPanel) {
			this.easyColorPanel = easyColorPanel;
		}

}

⌨️ 快捷键说明

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