!
%
(
$
+
%
%
)
%
(array1[0], array2[0])
(array1[1], array2[1]) (array1[2], array2[2])….
Số đường thẳng vẽ được luôn nhỏ hơn số truyền vào thông số thứ 3 của phương thức
drawPoyline(). Ví dụ như: totalPoints - 1
Chương trình 6.5 minh hoạ các vẽ polyline.
Chương trình 6.5
import java.awt.*;
class PolyLines extends Frame
{
int x1[] = {50, 75, 95, 115, 135};
int y1[] = {50, 30, 60, 75, 60};
int x2[] = {67, 82, 95, 120, 135};
int y2[] = {150, 130, 160, 155, 180};
public PolyLines()//constructor
{
super ("Poly Lines");
setSize (300, 300);
setVisible (true);
}
public void paint (Graphics g)
{
g.drawPolyline (x1, y1, 5);
g.setFont (new Font("Times Roman", Font.BOLD, 15));
g.drawString("Current Color is black", 100, 100);
g.setColor(Color.blue);
g.drawPolyline (x2, y2, 5);
g.drawString ("Current Color is blue", 100, 200);
}
public static void main (String args[])
{
new PolyLines();
}
}
Kết quả của chương trình được minh hoạ ở hình 6.7