1. 方法
drawLine(int x1, int y1, int x2, int y2)
通过Graphics可以设置线是实线还是虚线
Graphics.SOLID :虚线
Graphics.DOTTED:实线
2. 问题:
1. 可否设置先的宽度
3. 实例
public class LineCanvas extends Canvas{ protected void paint(Graphics g) { // TODO Auto-generated method stub clear(g); g.setColor(255,0,0); //设置画笔的颜色 g.drawLine(1, 30, 100, 10); //绘制线: 开始点的坐标和结束点的坐标g g.setStrokeStyle(Graphics.DOTTED); //设置画笔的类型为实心的 g.setColor(125,125,125); g.drawLine(1, 50, 100, 50); g.setStrokeStyle(Graphics.SOLID); } private void clear(Graphics g){ g.setColor(255,255,255); g.fillRect(0, 0, getWidth(), getHeight()); } }