Java Graphics – Draw A Circle in Java

 

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:

  1. java.awt.Graphics
  2. javax.swing.JFrame
  3. 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:

  1. Title
  2. Border
  3. 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:

   

  1. drawOval(): This method is used to draw the Shape of the Circle / Oval.
  2. setColor(): This methods helps to set the Color to be filled inside the Circle / Oval.
  3. 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

   

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

Java Graphics - Draw A Circle in Java Programming using AWT, JFrame and Graphics

If you have any Compilation Errors or Doubts about this Code To Draw A Circle in Java Programming, Comment Section is awaiting you.

One thought on “Java Graphics – Draw A Circle in Java

  1. Mounir

    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

    Reply

Let's Discuss