2016-12-14 173 views

回答

1

要绘制一个圆角矩形,你需要扩展Figure而且这个数字里面绘制圆角边框

免责声明一个矩形 - 这是我使用的代码的简化版本一个圆角的长方形here。很确定它会工作,但我没有测试它)

public class RoundedRectangle extends Figure { 
    private final RoundedRectangle rectangle; 

    public RoundedRectangle() { 
     super(); 
     setLayoutManager(new XYLayout()); 
     rectangle = new RoundedRectangle(); 
     rectangle.setCornerDimensions(new Dimension(20, 20)); // This is where the rounding happens 
     // Anything else you want to customize 
     add(rectangle); 
    } 

    @Override 
    protected void paintFigure(Graphics graphics) { 
     Rectangle r = getBounds().getCopy(); 
     setConstraint(rectangle, new Rectangle(0, 0, r.width, r.height)); 
    } 
}