/*Program for background color changing using scrollbar*/
import java.awt.*;
import java.awt.event.*;
class sroll extends Frame implements AdjustmentListener,ActionListener
{
Button b;
Scrollbar sr,sg,sb;
Label lr,lg,lb;
public sroll()
{
b=new Button("EXIT:");
lr=new Label("RED:");
lg=new Label("GREEN:");
lb=new Label("BLUE:");
sr=new Scrollbar(Scrollbar.HORIZONTAL,0,1,1,255);
sg=new Scrollbar(Scrollbar.HORIZONTAL,0,1,1,255);
sb=new Scrollbar(Scrollbar.HORIZONTAL,0,1,1,255);
b.addActionListener(this);
sr.addAdjustmentListener(this);
sg.addAdjustmentListener(this);
sb.addAdjustmentListener(this);
setLayout(new FlowLayout());
add(lr); add(sr); add(lg); add(sg); add(lb); add(sb);
add(b);
}
public void actionPerformed(ActionEvent a1)
{
System.exit(0);
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
int r=sr.getValue();
int g=sg.getValue();
int b=sb.getValue();
Color c=new Color(r,g,b);
setBackground(c);
}
public static void main(String args[])
{
sroll a=new sroll();
a.setSize(200,200);
a.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
class sroll extends Frame implements AdjustmentListener,ActionListener
{
Button b;
Scrollbar sr,sg,sb;
Label lr,lg,lb;
public sroll()
{
b=new Button("EXIT:");
lr=new Label("RED:");
lg=new Label("GREEN:");
lb=new Label("BLUE:");
sr=new Scrollbar(Scrollbar.HORIZONTAL,0,1,1,255);
sg=new Scrollbar(Scrollbar.HORIZONTAL,0,1,1,255);
sb=new Scrollbar(Scrollbar.HORIZONTAL,0,1,1,255);
b.addActionListener(this);
sr.addAdjustmentListener(this);
sg.addAdjustmentListener(this);
sb.addAdjustmentListener(this);
setLayout(new FlowLayout());
add(lr); add(sr); add(lg); add(sg); add(lb); add(sb);
add(b);
}
public void actionPerformed(ActionEvent a1)
{
System.exit(0);
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
int r=sr.getValue();
int g=sg.getValue();
int b=sb.getValue();
Color c=new Color(r,g,b);
setBackground(c);
}
public static void main(String args[])
{
sroll a=new sroll();
a.setSize(200,200);
a.setVisible(true);
}
}
No comments:
Post a Comment