Janki
drwapolyline() and drawOval()
1 Answer(s)      5 years and 6 months ago
Posted in : Java Beginners

Explain drwapolyline() and drawOval() Methods with suitable example.

Ads

View Answers

February 22, 2011 at 3:13 PM


Java drwapolyline() and drawOval()

The method drawPolyline draws a sequence of connected lines defined by arrays of x and y coordinates. Each pair of (x, y) coordinates defines a point. The figure is not closed if the first point differs from the last point.

The method drawOval() draws the outline of an oval. The result is a circle or ellipse.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class DrawShapes extends JPanel{
    public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setPaint(Color.red);
    int[] x = {25, 75, 125, 85, 125, 75, 25, 65};
      int[] y = {50, 90, 50, 100, 150, 110, 150, 100};
    g2d.drawPolyline(x,y,8 );
    g2d.drawOval(150,50,100,100 );

    }
    public static void main(String s[]) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new DrawShapes());
    frame.setSize(300, 200);
    frame.show();
  }
}









Related Tutorials/Questions & Answers:

Ads

Advertisement