Code for the Ellipse
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Font;
public class circle2 extends
java.applet.Applet {
public void paint(Graphics g) {
Font f = new Font("TimesRoman",
Font.PLAIN, 12);
Font f2 = new Font("TimesRoman",
Font.BOLD, 20);
g.drawString("(50,60)",10,55);
g.drawString("- 100 -",85,55);
g.drawString("150",20,140);
g.setColor(Color.cyan);
g.drawLine(50,60,40,60);
g.drawLine(50,60,50,50);
g.drawLine(50,55,150,55);
g.drawLine(45,60,45,210);
g.drawLine(150,60,150,50);
g.drawLine(40,210,50,210);
g.setColor(Color.red);
g.drawOval(50,60,100,150);
g.setFont (f2);
g.setColor(Color.black);
g.drawString("g.drawOval
(50,60,100,150);",20,260);
}
}
|
This allows us
to use the Graphics methods of the Java Abstract
Windowing toolkit. We want to generate an applet . The paint method is how an applet draws objects on the screen. These loops draw the vertical and Two fonts are defined as f and f2. The numerical labels are drawn and the color is set. The various lines in the applet are drawn. After the color is changed to red, an oval is inscribed inside a rectangle. The top left corner of the rectangle is located 50 pixels to the right and 60 pixels down in the applet window. The width and length are 100 and 150, respectively. The caption is drawn under the oval. |