Menu Bar

Horizontal Scrollable Menu

ads

Search This Blog

how to create color changer mini-project using java applet with source code



https://www.myprogrammingschool.com/search/label/Project
color changer

Source Code


import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.Color;
class ColourChange extends Applet implements ActionListener
{
Frame f;
/* public void init()
{
f.setbackground(Color.pink);
}
*/

Button b1,b2,b3;
ColourChange()
{
f=new Frame("Colour");

b1=new Button("red");
b2=new Button("yellow");
b3=new Button("green");

f.setVisible(true);
f.setSize(400,400);
f.setLayout(new FlowLayout());
f.setBackground(Color.black);

f.add(b1);
f.add(b2);
f.add(b3);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent  e)
{
if(e.getSource().equals(b1))
{
f.setBackground(Color.red);
}
if(e.getSource().equals(b2))
{
f.setBackground(Color.yellow);
}
 if(e.getSource().equals(b3))
{
f.setBackground(Color.green);
}
}
public static void main(String...aa)
{
new ColourChange();
}
}

No comments:

ads3