Q:

Java Applet - Change Background Color using Button

0

This Program is used to change the Background Color through Button Component.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class colorbutt extends Applet
{
Label l;
TextField tf; 
Button b1,b2;

public void init()
{
b1 = new Button("Color");
b2 = new Button("No Color");

add(b1); add(b2);

b1.addActionListener(new s());
b2.addActionListener(new s());
}

class s implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
setBackground(Color.red);
}

if(e.getSource()==b2)
{
setBackground(Color.white);
}
}
}
}

/* <applet code = "colorbutt.class" height = 300 width = 300>
</applet> */

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now