我想在每次用户点击单选按钮时更改形状的大小。但是我有中小问题,但是对于大型我不知道这样做的正确方法。罐头有人帮我这个。
protected int radius = 1;
public void circle(Graphics shapes)
{
shapes.setColor(color);
shapes.fillOval(250,100, 100/radius, 100/radius);
}
public void rectangle(Graphics shapes)
{
shapes.setColor(color);
shapes.fillRect(250,100,100/radius,100/radius);
}
public void square(Graphics shapes)
{
shapes.setColor(color);
shapes.fillRect(200,100,200/radius,100/radius);
}
public void triangle(Graphics shapes)
{
int[] x = new int[3];
int[] y = new int[3];
x[0]=300; x[1]=350; x[2]=250;
y[0]=100/radius; y[1]=200; y[2]=200;
Polygon polygon = new Polygon(x,y,3);
shapes.setColor(color);
shapes.fillPolygon(polygon);
}
public void actionPerformed(ActionEvent click) {
if(click.getSource() == small){
radius = 1*2;repaint();
}else if(click.getSource() == medium){
radius = 1; repaint();
}
else if(click.getSource() == large){
radius = 1; repaint();
}
}