In: Computer Science
Write an applet in Java that creates a yellow colored filled circle on screen. Inside this circle the word “GO” with Arial font and size 24, bold face needs to be printed. Justify your syntax.
Here two file are given to run the java Applet Program,
To run the java applet program you need to compile the myApplet.java file in cmd.exe as,
After the compilation of the .java file you need to run the applet by the given below command in cmd.exe,
//myApplet.java file.
import java.awt.*; //Importing the awt packages that contain the
various graphic classes.
import java.applet.Applet; //Importing the Applet class to run the
applet.
public class myApplet extends Applet{ //myApplet class
starts.
public void paint(Graphics g){ //Method paint that
will draw the circle and text on the applet.
setForeground(Color.YELLOW);
//Setting the color of circle as yellow.
g.fillOval(180,150,150,150); //Draw
the circle with 150 radius on the applet screen.
Font font = new Font("Arial",
Font.PLAIN + Font.BOLD , 24); //Creating the object of front as
Arial with size 24.
g.setFont(font); //Setting
respective font.
g.setColor(Color.BLACK); //Setting
the color for text as black.
g.drawString("GO",235,235);
//Draw the text "GO" on the applet screen.
} //End of paint method.
} //End of myApplet class.
<!-- /myApplet.html file -->
<html>
<body>
<!-- Setting the Applet with width and height as 500
-->
<applet code="myApplet.class" width="500" height="500">
</applet>
</body>
</html>
Output of the following code is given below :