|
Background
Color Button Window
import java.awt.*;
public class ButtonWindow extends Frame
{
String greet;
public ButtonWindow()
{
setBackground(Color.gray);
Button r,g,b,o,y,v;
r = new Button ("Red") ;
g = new Button ("Green") ;
b = new Button ("Blue") ;
o = new Button ("Orange") ;
y = new Button ("Yellow") ;
v = new Button ("Magenta") ;
add(r);
add(g);
add(b);
add(o);
add(Y);
add(v);
r.reshape(100,300,25,25);
g.reshape (150, 300, 25, 25) ;
b.reshape (200, 300, 25, 25) ;
o.reshape(250,300,25,25);
y.reshape(300,300,25,25);
v.reshape(350,300,25,25);
boolean handleEvent(Event e)
{
If (e.id == Event.WINDOW_DESTROY)
System.exit(0);
return(super.handleEvent(e));
}
public boolean action(Event e,Object arg)
if (arg.equals ("Red") )
{
setBackground(Color.red);
}
else if (arg.,equals ("Green·") ) {
{
setBackground(Color.green);
}
else if (arg.equals ("Blue") )
{
setBackground(Color.blue);
}
else if (arg.equals ("Orange") )
{
setBackground(Color.orange);
}
else if (arg.equals ("Yellow") )
{
setBackground(Color:yellow);
}
else if (arg.equals ("Magenta") )
{
setBackground(Color.magenta);
}
repaint();
return(super.action(e,arg).);
}
public static void main(String arg[J)
{
ButtonWindow b;
b = new ButtonWindow();
b.resize(600,600);
b.show();
}
}
Output
: This code will Create a Frame with six buttons representing any
six colors as described.
|