Tuesday, 29 November 2016

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>


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

No comments:

Post a comment