📄 pane.java
字号:
package com.moveShape;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Point;
import javax.swing.JButton;
import javax.swing.JPanel;
import com.diverseShapeFactory.DiverseCirFactory;
import com.diverseShapeFactory.DiverseRecFactory;
import com.diverseShapeFactory.DiverseShapeFactory;
/**
* this panel is used to layout the components
* @author Zhaojing
*
*/
public class Pane extends JPanel
{
private DrawPanel drawPanel;
/**
*
*/
public Pane()
{
//layout
this.setLayout(new GridLayout(1,2));
/*--------------------start-----------------------------*/
//the panel to draw the shapes
drawPanel=new DrawPanel();
//circle
Shape cir1=DiverseCirFactory.createBorderedShape(new MyCircle(new Point(60,60),30));
Shape cir2=DiverseCirFactory.createCrossedShape(new MyCircle(new Point(140,60),30));
Shape cir3=DiverseCirFactory.createTextedShape(new MyCircle(new Point(220,60),30));
Shape cir4=DiverseCirFactory.createCrossedBorderedShape(new MyCircle(new Point(300,60),30));
Shape cir5=DiverseCirFactory.createCrossedTextedShape(new MyCircle(new Point(60,140),30));
Shape cir6=DiverseCirFactory.createBorderedTextedShape(new MyCircle(new Point(140,160),30));
Shape cir7=DiverseCirFactory.createCrossedTextedBorderedShape(new MyCircle(new Point(220,180),30));
//rec
Shape rec1=DiverseRecFactory.createBorderedShape(new MyRectangle(new Point(30,280),60,50));
Shape rec2=DiverseRecFactory.createCrossedShape(new MyRectangle(new Point(110,280),60,50));
Shape rec3=DiverseRecFactory.createTextedShape(new MyRectangle(new Point(190,280),60,50));
Shape rec4=DiverseRecFactory.createCrossedBorderedShape(new MyRectangle(new Point(260,280),60,50));
Shape rec5=DiverseRecFactory.createCrossedTextedShape(new MyRectangle(new Point(30,400),60,50));
Shape rec6=DiverseRecFactory.createBorderedTextedShape(new MyRectangle(new Point(110,440),60,50));
Shape rec7=DiverseRecFactory.createCrossedTextedBorderedShape(new MyRectangle(new Point(190,480),60,50));
//add circle
drawPanel.addShape(cir1);
drawPanel.addShape(cir2);
drawPanel.addShape(cir3);
drawPanel.addShape(cir4);
drawPanel.addShape(cir5);
drawPanel.addShape(cir6);
drawPanel.addShape(cir7);
//add rec
drawPanel.addShape(rec1);
drawPanel.addShape(rec2);
drawPanel.addShape(rec3);
drawPanel.addShape(rec4);
drawPanel.addShape(rec5);
drawPanel.addShape(rec6);
drawPanel.addShape(rec7);
//drawPanel.addShape(rectangle);
//drawPanel.addShape(circle2);
/*--------------------end-----------------------------*/
/*--------------------start-----------------------------*/
//the panel to add the observers
JPanel sidePanel=new JPanel();
sidePanel.setLayout(new GridLayout(2,1));
ShowColorNameState nameState=new ShowColorNameState();
ShowColorState colorState=new ShowColorState();
//add register
//cir1.getDescrption();
//cir1.registerObserver(nameState);
//cir1.registerObserver(colorState);
//rectangle.registerObserver(nameState);
//rectangle.registerObserver(colorState);
sidePanel.add(nameState);
sidePanel.add(colorState);
/*--------------------end-----------------------------*/
/*--------------------start---------------------------*/
//add all the components
this.add(drawPanel);
this.add(sidePanel);
/*--------------------end---------------------------*/
}
/**
*
* @param shape
*/
public void addShape(Shape shape)
{
drawPanel.addShape(shape);
}
public void moveAll()
{
drawPanel.moveAll();
}
//save the state
public void save(String fileName)
{
drawPanel.save(fileName);
}
public DrawPanel getDrawPanel()
{
return drawPanel;
}
public void unite()
{
drawPanel.unite();
}
public void divide()
{
drawPanel.divide();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -