1. 程式人生 > >JAVA畫板課程設計---總之歲月漫長,然而值得等待。

JAVA畫板課程設計---總之歲月漫長,然而值得等待。

在校大學生的一份辛苦勞動成果寫了一個小畫板程式。

XI`AN TECHNOLOGICAL UNIVERSITY

實驗報告

課程設計名稱 畫板軟體                      

專    業:    軟體工程                

班    級:    17060209                

姓    名:    楊路恆                  

學    號:    17060209117             

指導教師:    徐飛                    

成    績:                            

    2018      6   26   

專業

軟體工程

班級

17060209

姓名

楊路恆

學號

17060209117

實驗課程

畫板軟體

指導教師

徐飛

實驗日期

2018.6.26

同實驗者

徐飛

實驗專案

JAVA實現畫板軟體

實驗裝置及器材

計算機

西安工業大學實驗報告

設計任務書

學習了《Java面向物件程式設計》的課程,為了更進一步的提高我們對Java的深入學習,進行了課程設計,我所選擇課程設計是利用Java的GUI實現畫圖應用程度。其目的是通過本課程設計使我們能夠較全面的掌握面向物件程式設計的有關概念和開發方法,以便能較全面地理解、掌握和綜合運用所學的知識,提高自身的程式設計能力。

運用JAVA語言,實現介面畫板,進行簡單圖形繪製。

主要利用java語言設計開發一個小型的畫圖應用程式,至少具有如下功能:可以進行繪畫,有顏色的選擇,可以繪製直線、曲線、橢圓、矩形,操作介面要符合使用者的一般習慣。

本軟體開發平臺:JAVA

本軟體開發環境:IntelliJ IDEA Community Edition 2018.1.4 x64

本軟體執行平臺:Windows 10

本組課題

2.1課題

JAVA繪圖板課程設計。

1.編寫畫板介面。

2.新增元件監聽、滑鼠監聽功能。

3.編寫圖形類的介面。

4.編寫各種圖形類並實現圖形的重繪。

3   程式功能簡介

1)利用Java設計一個畫圖應用程式;

2)可繪製直線、曲線、橢圓、矩形;

3)可改變線條顏色;

使用者可以在介面上通過點選各個不同的按鈕,選擇實現繪製的是哪種圖形和顏色,也可以清除畫板,程式將自動把所繪製的圖形類放在一個集合中,最大化和最小化後遍歷該集合,圖形實現重繪。

畫板畫筆分為兩種,一種是Graphics,一種是Graphics 2D。可以用來畫基本圖形還有噴桶、橡皮擦效果。

主體內容

1.繪圖工具已經廣為使用,利用JAVA語言編寫的畫板可以滿足基本的圖形要求,為了實現繪製矩形、圓形、橢圓、多邊形、直線、曲線鉛筆等基本圖形,在此程式中定義上述幾種圖形類,實現編寫的一個重繪介面。

2.在使用者介面GUI類中,繼承了JFrame類,新增各種按鈕、兩個面板,分別用來畫圖和存放按鈕元件,介面採用流式佈局,為元件新增編寫好的事件監聽機制。

3.在事件監聽DrawListener類中實現了MouseListener、MouseMotionListener、ActionListener監聽介面,並重寫其繪圖方法。

4.在事件監聽類中,定義一個字串str用來儲存按鈕按下時上面的內容,如果無文字,則判斷為顏色按鈕,把畫筆顏色color設定為按鈕顏色;有文字的話根據按鈕文字的不同,去呼叫不同的圖形類方法,並在繪製圖形後儲存在集合中。

5.在介面GUI類中呼叫DrawListener類,新建draw引用,為每個按鈕新增該事件引用並呼叫ArrayList集合類,遍歷所繪製的圖形類,進行重繪。

4.2.1系統結構分析圖

                            畫圖區                            畫筆顏色

筆刷

                           工具欄               設定           橡皮檫

                                                             清除面板

                          形狀選擇

矩形      實矩形   橢圓       實橢圓       直線    曲線     多邊形

4.2.2程式結構流程圖

                        NetJavaShape介面

       圖形類            事件監聽類                 其它類

                         主介面類

4.2.3結構流程圖

開始

                              Gui類

                           點選按鈕

                        DrawListener類               NetJavaShape介面

                              判斷

                             按鈕               顏色類

圖形類

       畫圖                        結束

1.繪圖主介面模組

1主類(GUI)用來生成主介面。

2完成畫圖的框架。

3主介面由畫圖區、工具欄組成,佈局格式採用BorderLayout佈局。

4介面截圖

2.繪圖類模組

1在程式中用到了JAVA的封裝、多型、繼承特性,定義了NetJavaShape介面,裡面寫了redraw()抽象方法。

2分別構造不同的圖形類:直線類(reline)、實矩形類(refilljuxing)、曲線類(requxian)、射線類(reshexian)、矩形類(rejuxing)、折線類(rezhexian)、橢圓類(retuoyuan)、實橢圓類(refilltuoyuan)。

3每個圖形類都實現NetJavaShape介面中的redraw()方法,每個方法中根據形狀選擇不同的繪製方法函式。

4每個類可以在事件監聽類中新建不同的物件引用,根據按鈕選擇不同可以呼叫不同的圖形類畫法。

5部分程式碼

import java.awt.*;                //定義一個介面,裡面用抽象方法讓圖形類實現該介面

public interface NetJavaShape{

    public abstract void redraw();

}

  1. 滑鼠及元件的事件監聽模組

1 DrawListener實現ActionListener、MouseListenerMouseMotionListener介面。

  2定義List<NetJavaShape> getShapeArr()、setG(Graphics g)、setNowColor(JButton nowColor)方法用來獲取圖形類集合、畫筆、當前按鈕顏色。

  3在actionPerformed(ActionEvent e)方法中用來判斷按鈕按下時要執行哪種命令。mouseDragged(MouseEvent e)方法中用來執行射線、曲線、橡皮檫、筆刷操作。mousePressed(MouseEvent e)、mouseReleased(MouseEvent e)方法中記錄當前滑鼠點選和釋放的位置座標。mouseReleased(MouseEvent e)中執行矩形、橢圓、實橢圓、折線、直線、實矩形、噴桶、多邊形、擦除面板操作。

  4 mouseClicked(MouseEvent e)方法中執行多邊形連線操作。

  5模組程式碼

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import java.util.List;

public class DrawListener implements MouseListener,ActionListener,MouseMotionListener {               //實現滑鼠、元件事件監聽介面

    private Color color;                                                                              //顏色引用

    private Graphics g;                                                                               //建立畫筆

    private Graphics2D g1;

    private String str;                                                                               //字串用來存放按鈕上的內容

    private int x1,x2,y1,y2,x3,y3,x4,y4,x,y,startx1,starty1,startx2,starty2;                          //座標定義

    private JButton nowColor;                                                                         //當前選中顏色按鈕

    private List<NetJavaShape> shapeArr=new ArrayList<NetJavaShape>();                                //存放圖形類的集合

    //建立各種圖形類物件引用

    private reline shapeline;

    private refilljuxing shapefilljuxing;

    private requxian shapequxian;

    private reshexian shapeshexian;

    private rejuxing shapejuxing;

    private rezhexian shapezhexian;

    private retuoyuan shapetuoyuan;

    private refilltuoyuan shapefilltuoyuan;

    private clear reclear;

    private bishua bs;

    private boolean flag=false;                                                                      //定義布林變數用於判斷多邊形是否繪製

    private Random rand=new Random();                                                                //用隨機數刻畫噴桶的範圍大小

    public List<NetJavaShape> getShapeArr() {

        return shapeArr;

    }                                     //獲取圖形集合的方法

    public void setG(Graphics g){

        this.g=g;

    }                                                       //獲取畫筆方法

    public void setNowColor(JButton nowColor){

        this.nowColor=nowColor;

    }                            //獲取當前顏色按鈕

    @Override

    public void actionPerformed(ActionEvent e) {

        //獲取按鈕上的字串

        if ("".equals(e.getActionCommand())){                                                       //點選的是顏色按鈕

            JButton button=(JButton)e.getSource();

            color=button.getBackground();

            nowColor.setBackground(color);

        }

        else str=e.getActionCommand();                                                              //點選的是圖形按鈕

    }

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import java.util.List;

import javax.swing.*;

class Gui extends JFrame{                                             //主介面類

    DrawListener draw=new DrawListener();                             //建立事件監聽類物件

    private Graphics g;                                               //畫筆是一個元件

 private List<NetJavaShape> shapeArray=new ArrayList<NetJavaShape>();

    JPanel panel;

    JPanel panel2;

    JButton button1,button2,button3,button4,button5,button6,button7,button8,button9,button10,clear,nowcolor,brush,eraser;

    JButton red,green,yellow,blue,purple,pink;

    public Gui(){                                                          //構造方法初始化物件

        panel=new JPanel();

        panel2=new JPanel(new GridLayout(15,6,10,10));         //網格佈局

        button1=new JButton("矩形");

        button2=new JButton("橢圓");

        button3=new JButton("實橢圓");

        button4=new JButton("直線");

        button5=new JButton("射線");

        button6=new JButton("曲線");

        button7=new JButton("實矩形");

        button8=new JButton("折線");

        button9=new JButton("多邊形");

        button10=new JButton("噴桶");

        brush=new JButton("筆刷");

        eraser=new JButton("橡皮擦");

        clear=new JButton("擦除面板");

        nowcolor=new JButton();

        nowcolor.setBackground(Color.black);

        red=new JButton();

        red.setBackground(Color.red);

        green=new JButton();

        green.setBackground(Color.green);

        yellow=new JButton();

        yellow.setBackground(Color.yellow);

        blue=new JButton();

        blue.setBackground(Color.blue);

        purple=new JButton();

        purple.setBackground(Color.magenta);

        pink=new JButton();

        pink.setBackground(Color.pink);

        //為按鈕新增事件類物件

        button1.addActionListener(draw);

        button2.addActionListener(draw);

        button3.addActionListener(draw);

        button4.addActionListener(draw);

        button5.addActionListener(draw);

        button6.addActionListener(draw);

        button7.addActionListener(draw);

        button8.addActionListener(draw);

        button9.addActionListener(draw);

        button10.addActionListener(draw);

        brush.addActionListener(draw);

        eraser.addActionListener(draw);

        clear.addActionListener(draw);

        red.addActionListener(draw);

        green.addActionListener(draw);

        yellow.addActionListener(draw);

        blue.addActionListener(draw);

        purple.addActionListener(draw);

        pink.addActionListener(draw);

        nowcolor.addActionListener(draw);

        panel2.add(button1);

        panel2.add(button2);

        panel2.add(button3);

        panel2.add(button4);

        panel2.add(button5);

        panel2.add(button6);

        panel2.add(button7);

        panel2.add(button8);

        panel2.add(button9);

        panel2.add(button10);

        panel2.add(brush);

        panel2.add(eraser);

        panel2.add(red);

        panel2.add(green);

        panel2.add(yellow);

        panel2.add(blue);

        panel2.add(purple);

        panel2.add(pink);

        panel2.add(clear);

        panel2.add(nowcolor);

        panel.setBackground(Color.white);

        panel.setPreferredSize(new Dimension(880,800));

        panel2.setPreferredSize(new Dimension(190,100));

        this.add(panel,BorderLayout.WEST);

        this.add(panel2,BorderLayout.EAST);

        this.setTitle("簡易畫板***楊路恆");

        this.setSize(1100,800);

        this.setLocation(500,200);

        this.setResizable(false);

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        this.setVisible(true);

        //在繪圖面板上畫筆

        panel.addMouseListener(draw);

        panel.addMouseMotionListener(draw);

        g=panel.getGraphics();

        draw.setG(g);

        draw.setNowColor(nowcolor);

        shapeArray=draw.getShapeArr();

    }

    @Override

    public void paint(Graphics g) {                   //進行圖形遍歷重繪

        super.paint(g);

        for (NetJavaShape a:shapeArray){

            a.redraw();

        }

    }

    public static void main(String []args){

            new Gui();

        }     //程式執行

}

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import java.util.List;

public class DrawListener implements MouseListener,ActionListener,MouseMotionListener {               //實現滑鼠、元件事件監聽介面

    private Color color;                                                                              //顏色引用

    private Graphics g;                                                                               //建立畫筆

    private Graphics2D g1;

    private String str;                                                                               //字串用來存放按鈕上的內容

    private int x1,x2,y1,y2,x3,y3,x4,y4,x,y,startx1,starty1,startx2,starty2;                          //座標定義

    private JButton nowColor;                                                                         //當前選中顏色按鈕

    private List<NetJavaShape> shapeArr=new ArrayList<NetJavaShape>();                                //存放圖形類的集合

    //建立各種圖形類物件引用

    private reline shapeline;

    private refilljuxing shapefilljuxing;

    private requxian shapequxian;

    private reshexian shapeshexian;

    private rejuxing shapejuxing;

    private rezhexian shapezhexian;

    private retuoyuan shapetuoyuan;

    private refilltuoyuan shapefilltuoyuan;

    private clear reclear;

    private bishua bs;

    private boolean flag=false;                                                                      //定義布林變數用於判斷多邊形是否繪製

    private Random rand=new Random();                                                                //用隨機數刻畫噴桶的範圍大小

    public List<NetJavaShape> getShapeArr() {

        return shapeArr;

    }                                     //獲取圖形集合的方法

    public void setG(Graphics g){

        this.g=g;

    }                                                       //獲取畫筆方法

    public void setNowColor(JButton nowColor){

        this.nowColor=nowColor;

    }                            //獲取當前顏色按鈕

    @Override

    public void actionPerformed(ActionEvent e) {

        //獲取按鈕上的字串

        if ("".equals(e.getActionCommand())){                                                       //點選的是顏色按鈕

            JButton button=(JButton)e.getSource();

            color=button.getBackground();

            nowColor.setBackground(color);

        }

        else str=e.getActionCommand();                                                              //點選的是圖形按鈕

    }

    @Override

    public void mouseEntered(MouseEvent e) {

        System.out.println("成功");

    }

    @Override

    public void mouseExited(MouseEvent e) {

    }

    @Override

    public void mouseDragged(MouseEvent e) {

        if ("射線".equals(str)) {                               //呼叫射線類方法

            shapeshexian = new reshexian(g, x1, y1, x2, y2, color);

            shapeshexian.redraw();

            shapeArr.add(shapeshexian);                       //把射線類物件新增到集合中

            x2 = e.getX();

            y2 = e.getY();

        }

        else if ("曲線".equals(str)){

            x=e.getX();

            y=e.getY();

            shapequxian=new requxian(g,x,y,x1,y1,color);

            shapequxian.redraw();

            shapeArr.add(shapequxian);

            x1=x;

            y1=y;

        }

        else if ("橡皮擦".equals(str)){

            g.setColor(Color.white);

            g1=(Graphics2D)g;

            x=e.getX();

            y=e.getY();

            g1.setStroke(new BasicStroke(10));

            g1.drawLine(x,y,x1,y1);

            x1=e.getX();

            y1=e.getY();

            g1.drawLine(x,y,x1,y1);

            g1.setStroke(new BasicStroke(1));

        }

            else if ("筆刷".equals(str)){

                x1=e.getX();

                y1=e.getY();

                x2=e.getX();

                y2=e.getY();

                bs=new bishua(g,x1,y1,x2,y2,color);

                bs.redraw();

                shapeArr.add(bs);

        }

    }

    @Override

    public void mousePressed(MouseEvent e) {

        g.setColor(color);                                      //獲取滑鼠按下的畫筆顏色和座標

        x=e.getX();

        y=e.getY();

        x1=e.getX();

        y1=e.getY();

    }

    @Override

    public void mouseReleased(MouseEvent e) {

        x2=e.getX();                                         //獲取滑鼠釋放時的座標

        y2=e.getY();

        if ("矩形".equals(str)) {

            //shapejuxing=new rejuxing(g,Math.min(x,x1),Math.min(y,y1),Math.abs(x-x1),Math.abs(y-y1),color);

            shapejuxing=new rejuxing(g,x,y,x2,y2,color);

            shapejuxing.redraw();

            shapeArr.add(shapejuxing);

        }

        else if ("橢圓".equals(str)){

            x1=e.getX();

            y1=e.getY();

            shapetuoyuan=new retuoyuan(g,Math.min(x,x1),Math.max(y,y1),Math.abs(x-x1),Math.abs(y-y1),color);

            shapetuoyuan.redraw();

            shapeArr.add(shapetuoyuan);

        }

        else if ("實橢圓".equals(str)){

            x1=e.getX();

            y1=e.getY();

            shapefilltuoyuan=new refilltuoyuan(g,Math.min(x,x1),Math.max(y,y1),Math.abs(x-x1),Math.abs(y-y1),color);

            shapefilltuoyuan.redraw();

            shapeArr.add(shapefilltuoyuan);

        }

        else if ("折線".equals(str)){

            shapezhexian=new rezhexian(g,x,y,x3,y3,color);

            shapezhexian.redraw();

            x3=e.getX();

            y3=e.getY();

            shapezhexian=new rezhexian(g,x,y,x3,y3,color);

            shapezhexian.redraw();

            shapeArr.add(shapezhexian);

        }

        else if ("直線".equals(str)){

            x4=e.getX();

            y4=e.getY();

            shapeline=new reline(g,x,y,x4,y4,color);

            shapeline.redraw();

            shapeArr.add(shapeline);

        }

        else if ("實矩形".equals(str)){

            x3=e.getX();

            y3=e.getY();

            shapefilljuxing=new refilljuxing(g,x,y,x3,y3,color);

            shapefilljuxing.redraw();

            shapeArr.add(shapefilljuxing);

        }

        else if ("噴桶".equals(str)) {

            x2 = e.getX();

            y2 = e.getY();

            for (int i = 0; i < 20; i++) {

                int r1 = rand.nextInt(30) - 10;

                int r2 = rand.nextInt(30) - 10;

                g.drawLine(x2 + r1, y2 + r2, x2 + r1, y2 + r2);

            }

        }

        else if ("多邊形".equals(str)){

            g.setColor(color);

            x2=e.getX();

            y2=e.getY();

            if (!flag) {                       //!flag說明為真

                g.drawLine(x1, y1, x2, y2);

                startx1=x1;

                starty1=y1;

                startx2=x2;

                starty2=y2;

                flag=true;

            }

        }

        else if ("擦除面板".equals(str)){

            reclear=new clear(g);

          reclear.redraw();

          shapeArr.add(reclear);

        }

    }

    @Override

    public void mouseClicked(MouseEvent e) {

        if(str.equals("多邊形")&&flag){                            //滑鼠點選時繪製連線多邊形

            g.setColor(color);

                         x2=e.getX();                              //獲取新的點的座標

                         y2=e.getY();

                        if(e.getClickCount()==2){                  //記錄點選次數,點選第二次後開始直線連線

                            g.drawLine(startx1,starty1,startx2,starty2);

                              flag=false;

                            }

                         g.drawLine(startx2,starty2,x2, y2);

                         startx2=x2;   //存下上個點的座標

                         starty2=y2;

                        }

    }

    @Override

    public void mouseMoved(MouseEvent e) {

    }

}

4.4.3介面圖形類

import java.awt.*;                //定義一個介面,裡面用抽象方法讓圖形類實現該介面

public interface NetJavaShape{

    public abstract void redraw();

}

class reline implements NetJavaShape{                //實現重繪直線圖形

    Graphics g;

    int x,y,x1,y1,x2,y2,x3,y3,x4,y4;

    Color color;

    public reline(Graphics g,int x1,int y1,int x2,int y2,Color color){    //構造方法初始化物件

        this.g=g;

        this.x1=x1;

        this.y1=y1;

        this.x2=x2;

        this.y2=y2;

        this.color=color;

    }

    @Override

    public void redraw() {                         //實現介面方法進行直線繪製

        g.setColor(color);

        g.drawLine(x1,y1,x2,y2);

    }

}

    class refilljuxing implements NetJavaShape {                //實現重繪實矩形圖形

        Graphics g;

        int x, y, x1, y1, x2, y2;

        Color color;

        public refilljuxing(Graphics g, int x1, int y1, int x2, int y2, Color color) {

            this.g = g;

            this.x1 = x1;

            this.y1 = y1;

            this.x2 = x2;

            this.y2 = y2;

            this.color = color;

        }

        @Override

        public void redraw() {

            g.setColor(color);

            g.fillRect(x1,y1,x2,y2);                          //實現介面方法進行實矩形繪製

        }

    }

        class requxian implements NetJavaShape {                //實現重繪曲線圖形

            Graphics g;

            int x, y, x1, y1, x2, y2;

            Color color;

            public requxian(Graphics g, int x1, int y1, int x2, int y2, Color color) {

                this.g = g;

                this.x1 = x1;

                this.y1 = y1;

                this.x2 = x2;

                this.y2 = y2;

                this.color = color;

            }

            @Override

            public void redraw() {                                  //實現介面方法進行曲線繪製

                g.setColor(color);

                g.drawLine(x1,y1,x2,y2);

            }

        }

            class reshexian implements NetJavaShape {                //實現重繪射線方法

                Graphics g;

                int x, y, x1, y1, x2, y2;

                Color color;

                public reshexian(Graphics g, int x1, int y1, int x2, int y2, Color color) {

                    this.g = g;

                    this.x1 = x1;

                    this.y1 = y1;

                    this.x2 = x2;

                    this.y2 = y2;

                    this.color = color;

                }

                @Override

                public void redraw() {                          //實現介面方法進行射線繪製

                    g.setColor(color);

                    g.drawLine(x1, y1, x2, y2);

                }

            }

                class rejuxing implements NetJavaShape {                //實現重繪矩形方法

                    Graphics g;

                    int x, y, x1, y1, x2, y2;

                    Color color;

                    public rejuxing(Graphics g, int x1, int y1, int x2, int y2, Color color) {

                        this.g = g;

                        this.x1 = x1;

                        this.y1 = y1;

                        this.x2 = x2;

                        this.y2 = y2;

                        this.color = color;

                    }

                    @Override

                    public void redraw() {                                 //實現介面方法進行矩形繪製

                        g.setColor(color);

                         /*

                                窗體左上角的座標為(0,0)。所以左上角的座標是較小的.

                                所以只需呼叫一個取較小值的一個方法Math.min(x1,x2),Math.min(y1, y2)這樣分別賦給x,y就可以了。

                                長寬的設定,我們也不能直接就x2-x1,y2-y1,需要對其取一個絕對值

                                Math.abs(x1-x2),Math.abs(y1-y2)。這樣就可以正確的畫出.

                                 */

                        //g.drawRect(Math.min(x1,x2),Math.max(y1,y2),Math.abs(x1-x2),Math.abs(y1-y2));

                        g.drawRect(x1,y1,x2,y2);

                    }

                }

                    class rezhexian implements NetJavaShape {                //實現重繪折線圖形

                        Graphics g;

                        int x, y, x1, y1, x2, y2, x3, y3, x4, y4;

                        Color color;

                        public rezhexian(Graphics g, int x1, int y1, int x2, int y2, Color color) {

                            this.g = g;

                            this.x1 = x1;

                            this.y1 = y1;

                            this.x2 = x2;

                            this.y2 = y2;

                            this.color = color;

                        }

                        @Override

                        public void redraw() {

                            g.setColor(color);

                            g.drawLine(x1, y1, x2, y2);

                        }

                    }

                        class retuoyuan implements NetJavaShape {                //實現重繪橢圓圖形

                            Graphics g;

                            int  x1, y1, x2, y2;

                            Color color;

                            public retuoyuan(Graphics g, int x1, int y1, int x2, int y2, Color color) {

                                this.g = g;

                                this.x1 = x1;

                                this.y1 = y1;

                                this.x2 = x2;

                                this.y2 = y2;

                                this.color = color;

                            }

                            @Override

                            public void redraw() {

                                g.setColor(color);

                                /*

                                窗體左上角的座標為(0,0)。所以左上角的座標是較小的.

                                所以只需呼叫一個取較小值的一個方法Math.min(x1,x2),Math.min(y1, y2)這樣分別賦給x,y就可以了。

                                長寬的設定,我們也不能直接就x2-x1,y2-y1,需要對其取一個絕對值

                                Math.abs(x1-x2),Math.abs(y1-y2)。這樣就可以正確的畫出.

                                 */

                                g.drawOval(Math.min(x1,x2),Math.max(y1,y2),Math.abs(x1-x2),Math.abs(y1-y2));    //橢圓中x,y是左上角的位置,width,height是橫軸和縱軸用Math函式找最大值最小值

                            }

                        }

                                class refilltuoyuan implements NetJavaShape {                //實現重繪實橢圓圖形

                                        Graphics g;

                                        int x, y, x1, y1, x2, y2, x3, y3, x4, y4;

                                        Color color;

                                        public refilltuoyuan(Graphics g, int x1, int y1, int x2, int y2, Color color) {

                                            this.g = g;

                                            this.x1 = x1;

                                            this.y1 = y1;

                                            this.x2 = x2;

                                            this.y2 = y2;

                                            this.color = color;

                                        }

                                        @Override

                                        public void redraw() {

                                            g.setColor(color);

                                            g.fillOval(Math.min(x1,x2),Math.max(y1,y2),Math.abs(x1-x2),Math.abs(y1-y2));

                                        }

                                }

                                       /* class redubianxing implements NetJavaShape{                //實現重繪多邊形圖形

                                            Graphics g;

                                            int x1, y1, x2, y2;

                                            Color color;

                                            public redubianxing(Graphics g, int x1, int y1, int x2, int y2, Color color){

                                                this.g = g;

                                                this.x1 = x1;

                                                this.y1 = y1;

                                                this.x2 = x2;

                                                this.y2 = y2;

                                                this.color = color;

                                            }

                                            @Override

                                            public void redraw() {

                                            }

                                        }*/

                                                class clear implements NetJavaShape{        //實現畫板清除

                                                    Graphics g;

                                                    public clear(Graphics g){

                                                        this.g=g;

                                                    }

                                                    @Override

                                                    public void redraw() {

                                                        g.clearRect(0,0,8808,8800);

                                                    }

                                                }

                                                    class bishua implements NetJavaShape {     //實現筆刷功能

                                                        Graphics g;

                                                        Graphics2D g1;

                                                        int  x1, y1, x2, y2;

                                                        Color color;

                                                        public bishua(Graphics g, int x1, int y1, int x2, int y2, Color color) {

                                                            this.g1 = (Graphics2D) g;