我在Java中創建了一個簡單的Java程序,用於繪製圖形基元(線條,矩形,橢圓等),這些形狀通過拖動鼠標並存儲到屏幕上一個Shapes數組,所以我添加了一個滑塊來動態獲取筆畫大小(從1到20,1是默認值),但它更新了先前繪製的所有形狀。動態更新Java中形狀數組的筆畫大小
//注1:Graphics2D圖;在延長的JFrame
類定義//注2:strokeSize值是動態與滑塊
public void paint(Graphics g)
{
graph = (Graphics2D)g;
graph.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graph.setStroke(new BasicStroke(strokeSize));
for (Shape currentShape : shapes)
{
graph.setPaint(strokeCounter.next());
graph.draw(currentShape);
graph.setPaint(fillCounter.next());
graph.fill(currentShape);
}
//What follows are If statements for choosing a shape
//and actual methods for drawing them...
改變我的問題是:如何更新strokeSize,但僅限於形狀目前正在擬定?
'strokeSize'的定義在哪裏? –
在構造函數之前擴展JFrame的類。 – user3086760