applet drawLine() Example
This applet provides just a paint() method to draw strings and a line. To draw lines of more than one pixel thickness requires Java's 2D Graphics, examples for which can be found Graphics.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// drawLine() Example
import java.awt.*;
import javax.swing.*;
class DrawLineExample extends JApplet {
@Override public void paint(Graphics g) {
super.paint(g);
g.drawString("The streak of silver,", 100, 150);
g.drawString("the jet black metal ...", 100, 170);
g.drawLine(90, 135, 90, 180);
}
}
11 The parameters of the call to drawLine() are the x/y coordinates of the start and end of the line.
