This is a simple applet to set the background color to “CYAN” and display a message.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import java.awt.*;//Importing java.awt import java.applet.*;//Importing java.applet public class MyApplet extends Applet { public void init()//Initializing our applet { setBackground(Color.CYAN);//Setting background color to CYAN } public void paint(Graphics obj)//Paint method to display our message { obj.drawString("My Applet", 50, 50);//To display "My Applet" at 50x50 pixels } } |
In an applet init() is used to initialize the applet and paint() is used to display a message.
In the above code, setBackground() method is used to set the background color. The color to which it has to be set is passed as arguments.
The drawString() method is used to display messages.
thank you