2D shapes Example
This applet constructs two shape objects, an ellipse and a rectangle, using the classes Ellipse2D and Rectangle2D. These classes implement the Shape interface, which is the required class of the parameter of the fill() and draw() methods of g2.
Other classes implementing the shape interface can represent arcs, curves, lines, polygons, and so on.
// 2D Graphic Shapes: Ellipse2D & Rectangle2D Example
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
class Graphics2DExample extends JApplet {
@Override public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D)g;
Color c0=Color.orange, c1=Color.cyan;
Ellipse2D e=new Ellipse2D.Double(80,100,180,80);
g2.setPaint(c1);
g2.fill(e);
Rectangle2D r=new Rectangle2D.Double(50,50,100,200);
g2.setPaint(c0);
g2.setStroke(new BasicStroke(10));
g2.draw(r);
}
}
