Sunday, September 28, 2014

How to Draw a Circle in NetBeans

Instructions

    1

    Create a new project. Select "Java," then"Java Application." Create a main class named "DrawCircle." Click "Finish."

    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);

    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.

    4

    Press the green arrow in the top menu bar to run the program. A window containing a circle will appear.



No comments:

Post a Comment