How to Draw a Circle in NetBeans
By G.S. Jackson
Using NetBeans to write Java code can increase your productivity. NetBeans brings together all of the Java tools, from runtime to compiler, with program editing tools into one environment. You can perform a task that is relatively complex in Java programming, such as drawing a circle, efficiently using NetBeans.
Step 1
Create a new project. Select "Java," then"Java Application." Create a main class named "DrawCircle." Click "Finish."
Step 2
Enter the following code into the new "DrawCircle" class. This code represents a function that will draw a circle in a system window:
import java.awt.; import java.awt.event.; import java.awt.geom.*;
public class CircleDraw extends Frame { Shape circle = new Ellipse2D.Float(100.0f, 100.0f, 100.0f, 100.0f); Shape square = new Rectangle2D.Double(100, 100,100, 100); public void paint(Graphics g) { Graphics2D ga = (Graphics2D)g; ga.draw(circle); ga.fill(circle); ga.setPaint(Color.red); ga.draw(square); }
Step 3
Create the main function after the "CircleDraw" function:
public static void main(String args[]) { Frame frame = new CircleDraw(); frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent we){ System.exit(0); } }); frame.setSize(300, 250); frame.setVisible(true); }
This code will create a new system window, call the CircleDraw function, and draw the circle in the new window.
Step 4
Press the green arrow in the top menu bar to run the program. A window containing a circle will appear.
References
Writer Bio
G.S. Jackson specializes in topics related to literature, computers and technology. He holds a Bachelor of Arts in English and computer science from Southern Illinois University Edwardsville.