下面这个程序画不出三角形
可能是实现的方法不对
本人找了很多原因都无法解决,请问下要怎么修改才行
非常感谢!!!import java.awt.event.*; 
import java.awt.*;
import javax.swing.JFrame; 
import javax.swing.JPanel; 
import javax.swing.UIManager; 
public class  ShapeMain extends JFrame{
int x,y,x1,y1,x2,y2,x3,y3,width,height;
int[] xPoints;
    int[] yPoints;
boolean isFirstPoint = true;
//初始化开始画的是线
int drawType = PaintingGround.ROUND;
//初始化开始不是填充
boolean isFill = false;
//添加控件
Button btPolygon = new Button("三角形");
Button btRectangle = new Button("矩形");
Button btRound = new Button("圆");
Button btEllipse = new Button("椭圆");
Button tbFillState = new Button("填充");    Panel buttonPanel = new Panel();
PaintingGround paintingGround = new PaintingGround();
//Main Method
public static void main(String[] args) {
//设置显示外观
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e) {
e.printStackTrace();
}
new ShapeMain();
}

//构造函数
public ShapeMain() {
    //控件添加到控件组中
buttonPanel.add(btPolygon);
buttonPanel.add(btRectangle);
buttonPanel.add(btRound);
buttonPanel.add(btEllipse);
buttonPanel.add(tbFillState);    //设置容器及容器的整体布局
Container cp = this; cp.setLayout(new BorderLayout()); cp.add(BorderLayout.NORTH,buttonPanel);
cp.add(BorderLayout.CENTER,paintingGround); setLocation(300,150);
setSize(600,480);
setVisible(true);        setDefaultCloseOperation(EXIT_ON_CLOSE);
//添加鼠标触发事件
paintingGround.addMouseListener(new MouseAdapter() {
       public void mouseReleased(MouseEvent evn) {
isFirstPoint = true;
}
});
//对鼠标的输入进行判断并调用画图程序
paintingGround.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent evn) {
if(isFirstPoint) {
x1 = evn.getX();
y1 = evn.getY();
isFirstPoint = false;
}
else {
x2 = evn.getX();
y2 = evn.getY();
switch(drawType) {
    case PaintingGround.POLYGON:
//画线
x3 = (x1-x2)/2+x1;
                                                y3 = (int)(y2- (x1-x2)/2 * 1.732);
                                                int[] xpoints = {x1,x2,x3};
                                                int[] ypoints = {y1,y2,y3};
                                                paintingGround.drawPolygon(xPoints,yPoints,3);
break;
    case PaintingGround.RECTANGLE:
//画矫形
paintingGround.drawRect(x1,y1,x2-x1,y2-y1);
break;
    case PaintingGround.ROUND:
//画圆
//两点距离公式
int size = Math.abs((int)Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)));
paintingGround.drawRound(x1,y1,size);
break;
    case PaintingGround.ELLIPSE:
//画椭圆
paintingGround.drawEllipse(x1,y1,x2-x1,y2-y1);
break;
    default:
break;
}
}
}
});
    //各个控件的触发事件
 btPolygon.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent evn) {
  drawType = PaintingGround.POLYGON;
  }
  });
 
 btRectangle.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent evn) {
  drawType = PaintingGround.RECTANGLE;
  }
  });
 
 btRound.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent evn) {
  drawType = PaintingGround.ROUND;
  }
  });
 
 btEllipse.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent evn) {
  drawType = PaintingGround.ELLIPSE;
  }
  });
 
 tbFillState.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent evn) {
  isFill = tbFillState.isShowing();
  paintingGround.setFillState(isFill);
  }
  });
}
}class PaintingGround extends JPanel {
public static final int POLYGON = 1;
public static final int RECTANGLE = 2;
public static final int ROUND = 3;
public static final int ELLIPSE = 4;

private int x,y;
private int x1,y1,x2,y2,x3,y3;
private int width, height,size;
private int drawType = 0;
private boolean isFill = false;
private int[] xPoints;
    private int[] yPoints;
//构造函数
public PaintingGround() {
setBackground(Color.black);
}
//判断是用实心还是空心的,
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.white);
if(isFill) {
switch(drawType) {
case POLYGON:
g.fillPolygon(xPoints,yPoints,3); 
break;
case RECTANGLE:
g.fillRect(x,y,width,height);
break;
case ROUND:
g.fillOval(x,y,size,size);
break;
case ELLIPSE:
g.fillOval(x,y,width,height);
break;
default:
break;
}
}
else {
switch(drawType) {
case POLYGON:
g.fillPolygon(xPoints,yPoints,3); 
break;
case RECTANGLE:
g.drawRect(x,y,width,height);
break;
case ROUND:
g.drawOval(x,y,size,size);
break;
case ELLIPSE:
g.drawOval(x,y,width,height);
break;
default:
break;
}
}
}

 public void drawPolygon(int[] xPoints,int[] yPoints,int num) { 
         
        this.x1 = x1; 
        this.y1 = y1; 
        this.x2 = x2; 
        this.y2 = y2; 
        this.x3 = x3; 
        this.y3 = y3;
        int[] xpoints = {x1,x2,x3};
        int[] ypoints = {y1,y2,y3};
        num=3;

drawType = POLYGON;
repaint();
}
//具体的实现方式
public void drawRect(int x,int y,int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
drawType = RECTANGLE;
repaint();
}

public void drawRound(int x,int y,int size) {
this.x = x;
this.y = y;
this.size = size;
drawType = ROUND;
repaint();
}

public void drawEllipse(int x,int y,int width,int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
drawType = ELLIPSE;
repaint();
}

public void setFillState(boolean isFill) {
this.isFill = isFill;
}

}