This is a simple applet to set the background color to “CYAN” and display a message.
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.
Latest posts by Vlad (see all)
- Code jam “Tic-Tac-Toe-Tomek” solution in java - April 19, 2013
- Code jam “Minimum Scalar product” solution in java - March 18, 2013
- Code jam Store Credit solution in java - March 10, 2013