Lab #1
Write the code and execute the following Java program:

Write an applet that inputs from the user the radius of a circle as an integer number and draws the circle. It also outputs the value of the area of the circle. The area of a circle is given by pi times the square of the radius. Use the value 3.14 for pi. The user inputs the radius via a dialog message box. The user also inputs the coordinates of the origin of the circle (x and y coordinates ). The program outputs the value of the area on a message box also.

Submit your program to the TA and also demonstrate it to him.
  • Hint 1: You need to override the paint method of the JApplet class in order to draw the circle.
  • Hint 2: You need to call super.paint(g) as the first line of code within the paint method.
  • Hint 3: The circle is the same thing as an oval shape with two equal diameters.

The following is the sample application we demonstrated in class.
//
// File HellowWorld1.java
//
public class HelloWorld1 extends javax.swing.JComponent {

        public static void main(String[] args) {
                javax.swing.JFrame f = new javax.swing.JFrame("Hello, Java");
                f.setSize(200,200);
                f.getContentPane().add(new HelloWorld1());
                f.setVisible(true);
        }

        public void paintComponent(java.awt.Graphics g) {
                g.drawString("Hello, Java!", 25, 95);
        }
}