日本画形状 import java.awt.*; 导入java.awt.event.*; 导入javax.swing.*; @抑制警告(“串行”) 公共类shapeaplet扩展了JApplet{ //包含创建的所有形状 专用ShapeContainer

日本画形状 import java.awt.*; 导入java.awt.event.*; 导入javax.swing.*; @抑制警告(“串行”) 公共类shapeaplet扩展了JApplet{ //包含创建的所有形状 专用ShapeContainer ,java,Java,日本画形状 import java.awt.*; 导入java.awt.event.*; 导入javax.swing.*; @抑制警告(“串行”) 公共类shapeaplet扩展了JApplet{ //包含创建的所有形状 专用ShapeContainer ShapeContainer=新的ShapeContainer(); //主窗面板 专用面板leftPanel=新面板(); 专用面板右面板=新面板(); 专用面板按钮面板=新面板(); //右面板内的面板 专用面板形状面板=新面板(); 私有

日本画形状
import java.awt.*;
导入java.awt.event.*;
导入javax.swing.*;
@抑制警告(“串行”)
公共类shapeaplet扩展了JApplet{
//包含创建的所有形状
专用ShapeContainer ShapeContainer=新的ShapeContainer();
//主窗面板
专用面板leftPanel=新面板();
专用面板右面板=新面板();
专用面板按钮面板=新面板();
//右面板内的面板
专用面板形状面板=新面板();
私有字符串[]shapeNames={“Cicle”、“Rect”、“Polygon”、“Line”、“Cylinder”};
私人选择shapeChoice=新选择();
//定义要从中选择的颜色
JColorChooser colorChooser=新的JColorChooser(Color.BLACK);
//用于喷漆的物品
私人造型;
//创建形状按钮
ImageIcon图标圆形=新的ImageIcon(“circle.png”、“circle”);
JButton buttonCircle=新JButton(iconCircle);
ImageIcon图标行=新的ImageIcon(“line.png”、“line”);
JButton buttonLine=新JButton(iconLine);
ImageIcon iconRect=新的ImageIcon(“rect.png”、“Line”);
JButton buttonRect=新JButton(iconRect);
ImageIcon iconPolygon=新的ImageIcon(“polygon.png”,“Line”);
JButton buttonPolygon=新JButton(iconPolygon);
//创建其他工具按钮
JButton buttonClear=新JButton(“撤消”);
复选框checkBoxIsTheShapeFilled=新复选框(“已填充”);
//定义新画布
PaintingCanvas PaintingCanvas=新的PaintingCanvas();
//定义按钮操作的类
ButtonAction ButtonAction=新ButtonAction();
//保存选定的形状
私有int currentTool=4;
//保留鼠标位置的整数
私有int xPoint1,xPoint2=0,yPoint1,yPoint2=0;
@凌驾
公共void init(){
系统输出打印项次(“点”+xPoint1+yPoint2);
//设置位置、大小和属性
维度dim=Toolkit.getDefaultToolkit().getScreenSize();
int screenWidth=(int)dim.getWidth();
int屏幕高度=(int)dim.getHeight();
设置大小(屏幕宽度,屏幕高度-400);
//设置布局
此.setLayout(新的BorderLayout());
//创建形状的选项
对于(int i=0;i    import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

@SuppressWarnings("serial")
public class ShapeApplet extends JApplet{
    //contains all shapes that created
    private ShapeContainer shapeContaiter = new ShapeContainer();

    //main window panels
    private Panel leftPanel = new Panel();
    private Panel rightPanel = new Panel();
    private Panel buttomPanel = new Panel();

    //the panel inside right panel
    private Panel shapesPanel = new Panel();

    private String [] shapeNames = {"Cicle","Rect","Polygon","Line","Cylinder"};
    private Choice shapeChoice = new Choice();


    //defines the colors to choose from
    JColorChooser colorChooser = new JColorChooser(Color.BLACK);

    //item that will be use for painting
    private Shape shapeToDraw;

    //creating shapesButtons 
    ImageIcon iconCircle = new ImageIcon("circle.png", "Circle");
    JButton buttonCircle = new JButton(iconCircle);

    ImageIcon iconLine = new ImageIcon("line.png","Line");
    JButton buttonLine = new JButton(iconLine);

    ImageIcon iconRect = new ImageIcon("rect.png","Line");
    JButton buttonRect = new JButton(iconRect);

    ImageIcon iconPolygon = new ImageIcon("polygon.png","Line");
    JButton buttonPolygon = new JButton(iconPolygon);

    //creating the other tool buttons
    JButton buttonClear = new JButton("Undo");

    Checkbox checkBoxIsTheShapeFilled = new Checkbox("Filled");
    //defines the new canvas
    PaintingCanvas paintingCanvas = new PaintingCanvas();
    //defines the class for buttons actions
    ButtonAction buttonAction = new ButtonAction();

    //save the shape that selected
    private int currentTool = 4;
    //integers to keep the mouse location
    private int xPoint1, xPoint2 = 0, yPoint1,yPoint2 = 0;

    @Override
    public void init() {
        System.out.println("points" + xPoint1+yPoint2);
        //setting location , size and properties
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        int screenWidth = (int) dim.getWidth();
        int screenHeight = (int) dim.getHeight();
        this.setSize(screenWidth,screenHeight-400); 
        //setting layout
        this.setLayout(new BorderLayout());

        //creating the choices for  shapes
        for(int i = 0 ; i < shapeNames.length ; i++ )
            shapeChoice.add(shapeNames[i]);

        //defines left Panel and right Panel properties
        this.leftPanel.setBackground(Color.LIGHT_GRAY);
        this.leftPanel.setLayout(new GridLayout(5, 0));

        this.rightPanel.setBackground(Color.LIGHT_GRAY);
        this.rightPanel.setLayout(new BorderLayout());

        //adding items to the right panel
        this.rightPanel.add(colorChooser, BorderLayout.NORTH);

        //setting the shapes panel
        this.shapesPanel.setLayout(new GridLayout(3,3));
        this.shapesPanel.add(buttonCircle);
        this.shapesPanel.add(buttonLine);
        this.shapesPanel.add(buttonRect);
        this.shapesPanel.add(buttonPolygon);
        this.shapesPanel.add(checkBoxIsTheShapeFilled);

        //adding the shapes panel to the right Panel
        this.rightPanel.add(shapesPanel, BorderLayout.SOUTH);

        //adding items to the left panel
        this.leftPanel.add(buttonClear);

        //defines the location of each item on the main window
        this.add(leftPanel, BorderLayout.WEST);
        this.add(rightPanel, BorderLayout.EAST);
        this.add(buttomPanel,BorderLayout.SOUTH);
        this.add(paintingCanvas,BorderLayout.CENTER);   

        //setting button actions
        this.buttonCircle.addActionListener(buttonAction);
        this.buttonLine.addActionListener(buttonAction);
        this.buttonPolygon.addActionListener(buttonAction);
        this.buttonRect.addActionListener(buttonAction);
        this.buttonClear.addActionListener(buttonAction);


    }

    @Override
    public void start() {

        super.start();
    }

    @Override
    public void stop() {

        super.stop();
    }

    @Override
    public void destroy() {

        super.destroy();
    }

    public class PaintingCanvas extends Canvas implements MouseListener, MouseMotionListener
    {
        public PaintingCanvas()
        {
            addMouseListener(this);
        }
        @Override
        public void mouseClicked(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {

        }

        @Override
        public void mouseExited(MouseEvent e) {

        }

        @Override
        public void mousePressed(MouseEvent e) {

            xPoint1 = e.getX();
            yPoint1 = e.getY();
            xPoint2 = e.getX();
            yPoint2 = e.getY();

        }//end of mousePressed


        @Override
        public void mouseReleased(MouseEvent e) {

            xPoint2 = e.getX();
            yPoint2 = e.getY();



            shapeContaiter.add(shapeToDraw);

            System.out.println("Release");
            repaint();

        }


        @Override
        public void update(Graphics g) {
            paint(g);
        }//end of update

        @Override
        public void paint(Graphics g) {

            switch (currentTool)
            {   
                case 0:
                    //System.out.println("Circle pointsxy: " + xPoint1+","+yPoint1);
                    //System.out.println("Circle pointsx2y2: " + xPoint2+","+yPoint2);
                    shapeToDraw = new Circle(xPoint1 , yPoint1, new Point(xPoint2, yPoint2),colorChooser.getColor() , checkBoxIsTheShapeFilled.getState());
                    //System.out.println( "Circle pointsxy: " + shapeToDraw.getLocation());
                    shapeToDraw.draw(g);    

                    break;
                case 1:
                    shapeToDraw = new Line(xPoint1, yPoint1, new Point(xPoint2,yPoint2), colorChooser.getColor(), checkBoxIsTheShapeFilled.getState());
                    shapeToDraw.draw(g);

                    break;
                case 2:

                    break;
                case 3:
                    shapeToDraw = new Rect(xPoint1, yPoint1, new Point(xPoint2, yPoint2), colorChooser.getColor(), checkBoxIsTheShapeFilled.getState());
                    shapeToDraw.draw(g);

                    break;
                case 4:
                    break;
                default:
            }//end of switch

            System.out.println("Size of shapeContianer: "+shapeContaiter.size());
            System.out.println("pointsxy: " + xPoint1+","+yPoint1);
            System.out.println("pointsx2y2: " + xPoint2+","+yPoint2);


        }//end of paint
        @Override
        public void mouseDragged(MouseEvent e) {


        }
        @Override
        public void mouseMoved(MouseEvent e) {
            // TODO Auto-generated method stub

        }

    }//end of canvas

    public class ButtonAction implements ActionListener
    {

        @Override
        public void actionPerformed(ActionEvent e) {

            if ( e.getSource() == buttonCircle)
                currentTool = 0;
            else if ( e.getSource() == buttonLine)
                currentTool = 1;
            else if ( e.getSource() == buttonPolygon)
                currentTool = 2;
            else if ( e.getSource() == buttonRect)
                currentTool = 3;
            else if (e.getSource() == buttonClear){
                currentTool=4;
                if(shapeContaiter.isEmpty()) JOptionPane.showMessageDialog(buttonClear, "Nothing to delete");
                else {

                    Graphics g = paintingCanvas.getGraphics();

                    shapeContaiter.get(shapeContaiter.size()-1).setColor(Color.WHITE);
                    shapeContaiter.get(shapeContaiter.size()-1).draw(g);
                    shapeContaiter.remove(shapeContaiter.size()-1);

                    System.out.println("Size of shapeContianer: "+shapeContaiter.size());
                }
            }


        }//end of action performed

    }//end of ButtonClicked

}