Code To Draw A Circle in Java Programming
Here’s a Java Graphics Code To Draw A Circle in Java Programming using Swing and AWT. This Java Graphics Program makes a Circle with Color Filled inside it.
This Java Program To Draw A Circle includes the following Import Files:
- java.awt.Graphics
- javax.swing.JFrame
- java.awt.Color
A Frame in a Java Program is implemented as an instance of the JFrame Class. Java Applications that require Graphical User Interface (GUI) feature makes use of JFrame. JFrame is a Dialog Box or a Window that provides decorations such as:
- Title
- Border
- Button Components
These Button Components helps to Close the Windows Box and also helps to Iconify the Window.
The Important Methods in this Program are:
- drawOval(): This method is used to draw the Shape of the Circle / Oval.
- setColor(): This methods helps to set the Color to be filled inside the Circle / Oval.
- fillOval(): This method fills the Color within the Oval shape.
Also Read: Java Program To Find Public IP Address of the System
Code To Draw A Circle in Java Programming Language
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | package Circle; import java.awt.Graphics; import javax.swing.JFrame; import java.awt.Color; public class Circle extends JFrame { public Circle() { setTitle("Tutorial"); setSize(960,960); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void paint(Graphics g) { g.setColor(Color.GREEN); g.drawOval(480,480,200,200); g.fillOval(480, 480, 200, 200); } public static void main(String args[]) { Circle t = new Circle(); t.paint(null); } } |
Also Read: Swap Variables using BitWise Operators in Java
You can therefore draw different Shapes in Java by using proper built-in methods and by setting the Dimensions of the Shape to a proper format.
Output

If you have any Compilation Errors or Doubts about this Code To Draw A Circle in Java Programming, Comment Section is awaiting you.
Hi Tushar, I’m trying for practice to use The code mentioned above “Code To Draw A Circle in Java Programming Language”. I’m using this site :https://live.codecircle.com, but after copying the code I can’t see the result anywhere. Can you give me advices about the best way to continue learning and practicing Java and other programs?. Thanks a lot in advance. Mounir
How do you do this without creating a null pointer exception?