Hi,
In below java code I have used the methods of Graphics class along with different parameters:
Code:
import java.awt.Graphics;
import java.awt.geom.RoundRectangle2D;
import javax.swing.JFrame;
public class GraphicsDM extends JFrame {
Shape shps[] = new Shape[5];
public static void main(String aprgs[]) {
Draw2DObjects app = new Draw2DObjects();
}
public Draw2DObjects() {
add("Center", new MyCanvas());
shps[0] = new Line2D.Double(0.0, 0.0, 100.0, 100.0);
shps[1] = new Rectangle2D.Double(10.0, 100.0, 200.0, 200.0);
shps[2] = new Ellipse2D.Double(20.0, 200.0, 100.0, 100.0);
GeneralPath path = new GeneralPath(new Line2D.Double(300.0, 100.0, 400.0, 150.0));
path.append(new Line2D.Double(25.0, 175.0, 300.0, 100.0), true);
shps[3] = path;
shps[4] = new RoundRectangle2D.Double(350.0, 250, 200.0, 100.0, 50.0, 25.0);
setSize(300, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
class MyCanvas extends Canvas {
public void paint(Graphics graphics) {
Graphics2D g1 = (Graphics2D) graphics;
for (int i1 = 0; i1 < shps.length; ++i1) {
if (shps[i1] != null)
g1.draw(shps[i]);
}
} }
}
Bookmarks