如何设置java drawLine画的线的粗细
展开全部
使用java.awt.Graphics2D的setStroke方法就可以解决这个小问题
一个Graphics对象可以强制转化为Graphics2D类型(向下转型)
Graphics2D g2 = (Graphics2D)g; //g是Graphics对象
g2.setStroke(new BasicStroke(3.0f))
public class MyPanel extends JPanel{
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g; //g是Graphics对象
g2.setStroke(new BasicStroke(3.0f));
g2.setColor(Color.GREEN);
g2.drawLine(0, 0, 500, 600);
}
}
一个Graphics对象可以强制转化为Graphics2D类型(向下转型)
Graphics2D g2 = (Graphics2D)g; //g是Graphics对象
g2.setStroke(new BasicStroke(3.0f))
public class MyPanel extends JPanel{
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g; //g是Graphics对象
g2.setStroke(new BasicStroke(3.0f));
g2.setColor(Color.GREEN);
g2.drawLine(0, 0, 500, 600);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询