使用TextField设置drawLine的宽度

时间:2014-06-28 04:22:58

标签: java netbeans textfield

如何使用TextField设置线条的宽度,             g.drawLine(oldx,oldy,evt.getX(),evt.getY());
我需要设置一个初始值,然后让用户通过TextField更改它。 感谢

1 个答案:

答案 0 :(得分:0)

假设您正在使用swing,

该行的宽度由Graphics2D#setStroke方法设置。

g.setStroke(stroke);

在覆盖的paintComponent方法中调用此方法。


stroke可以初始化为

float width = 5f;    // Initial value.
stroke = new BasicStroke(width);

您应该将stroke个对象作为您的类的成员,其中paintComponent方法被覆盖。

现在您可以使用文本字段更新笔画对象。

希望这有帮助。

相关问题