当前位置: 技术问答>java相关
用Graphics 中的drawLine()方法可以画出"粗"一点的线吗?
来源: 互联网 发布时间:2015-09-13
本文导语: 就是说能否随意设置所画线的线宽? 谢谢! | 能: Graphics2D gg = (Graphics2D)g; gg.setStroke(new BasicStroke(2.0F,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); //2.0F是笔的粗细 //CAP_ROUND是线条端点 //JOIN_ROUND...
就是说能否随意设置所画线的线宽?
谢谢!
谢谢!
|
能:
Graphics2D gg = (Graphics2D)g;
gg.setStroke(new BasicStroke(2.0F,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
//2.0F是笔的粗细
//CAP_ROUND是线条端点
//JOIN_ROUND是点划线模式
gg.drawLine((int)x0,(int)y0,(int)x1,(int)y1);
gg.setStroke(new BasicStroke());
//设回原来的
Graphics2D gg = (Graphics2D)g;
gg.setStroke(new BasicStroke(2.0F,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
//2.0F是笔的粗细
//CAP_ROUND是线条端点
//JOIN_ROUND是点划线模式
gg.drawLine((int)x0,(int)y0,(int)x1,(int)y1);
gg.setStroke(new BasicStroke());
//设回原来的
|
fillRect 或 fill3DRect 不就可以划出任意寬度的先嗎