Java program to draw a Circle using Graphics2D class
KW.java
import java.awt.*; import java.awt.event.*; import java.awt.geom.*; class KW extends Frame { Shape circle=new Ellipse2D.Float(100.0f,100.0f,100.0f,100.0f); public void paint(Graphics g) { Graphics2D ga=(Graphics2D)g; ga.draw(circle); ga.setPaint(Color.blue); ga.fill(circle); } public static void main(String args[]) { Frame frame=new KW(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); frame.setSize(300,300); frame.setVisible(true); } }
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW![]()
Comments and Reactions
What Next?
Java program to draw a Rectangle using Graphics2D class
Java program to create an empty frame as an instance
Java program to print Hello World on a frame
Advertisement