Program to set background and foreground color of an Applet

To set the background and foreground color of an applet setBackground(Color c) and setForeground(Color c) methods are used respectively. You have to use these methods in applet's init( ) method. The output of program is shown in OUTPUT section.


PROGRAM
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;

public class SetBackColor extends Applet {
 
 public void init() 
 {
  setBackground(Color.cyan);
  setForeground(Color.red);
 }
 
 public void paint(Graphics g)
 {
  g.drawString("Hello Java",50,50);
 }
}

/* 
<applet code="SetBackColor" width=200 height=200>
</applet>
*/

OUTPUT

C:\>javac SetBackColor.java
C:\>appletviewer SetBackColor.java



Comments

Popular posts from this blog

Develop an Android application to display “Hello World!” on screen

Program to design an applet which draws a circle (having color BLUE) inside a triangle (having color YELLOW)

Build a Simple Android App to Display Student Details