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:
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:
- 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
public class Circle extends JFrame
public void paint(Graphics g)
g.fillOval(480, 480, 200, 200);
public static void main(String args)
Circle t = new Circle();
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.
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?