CHANGING BACKGROUND COLOR
/*
<applet code=color_change width=300 height=300>
</applet>
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class color_change extends Applet implements ActionListener
{
Button R,G,B;
public void init()
{
R=new Button(" RED ");
G=new Button(" GREEN ");
B=new Button(" BLUE ");
add(R);
add(G);
add(B);
R.addActionListener(this);
G.addActionListener(this);
B.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==R)
setBackground(Color.red);
if(ae.getSource()==G)
setBackground(Color.green);
if(ae.getSource()==B)
setBackground(Color.blue);
/*
if(ae.getActionCommand()==" RED ")
setBackground(Color.red);
if(ae.getActionCommand()==G.getLabel())
setBackground(Color.green);
*/
}
}
OUTPUT:
<applet code=color_change width=300 height=300>
</applet>
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class color_change extends Applet implements ActionListener
{
Button R,G,B;
public void init()
{
R=new Button(" RED ");
G=new Button(" GREEN ");
B=new Button(" BLUE ");
add(R);
add(G);
add(B);
R.addActionListener(this);
G.addActionListener(this);
B.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==R)
setBackground(Color.red);
if(ae.getSource()==G)
setBackground(Color.green);
if(ae.getSource()==B)
setBackground(Color.blue);
/*
if(ae.getActionCommand()==" RED ")
setBackground(Color.red);
if(ae.getActionCommand()==G.getLabel())
setBackground(Color.green);
*/
}
}
OUTPUT:
Comments
Post a Comment