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.

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

public class SetBackColor extends Applet {
 public void init() 
 public void paint(Graphics g)
  g.drawString("Hello Java",50,50);

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




Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.

Program to draw Smiley in Applet