記性總是不太好,容易忘事,一線線是由兩點組成的,啓點和終點,所有在drawLine方法中有四個參數來控制兩點,參數如下:
/**
* Draws a line, using the current color, between the points
* <code>(x1, y1)</code> and <code>(x2, y2)</code>
* in this graphics context's coordinate system.
* @param x1 the first point's <i>x</i> coordinate.
* @param y1 the first point's <i>y</i> coordinate.
* @param x2 the second point's <i>x</i> coordinate.
* @param y2 the second point's <i>y</i> coordinate.
*/
public abstract void drawLine(int x1, int y1, int x2, int y2);
x1,y1,x2,y2代表的是啥??時間久了特容易忘記。。做了個圖片容易記住:
在通過幾個示例說明下:
1.繪製一條橫線:
graphics.drawLine(0, 0, 125, 0)
2.繪製一條豎線:
graphics.drawLine(0, 0, 0, 125);
3.繪製一條斜線:
graphics.drawLine(0, 0, 250, 300);