/**
* @(#)ScrollDemo.java
*
*
* @anant mahale
* @version 1.00 2013/3/18
*/
import java.awt.*;
import java.awt.event.*;
class MyScroll extends Frame implements AdjustmentListener
{
private Scrollbar scr_red,scr_green,scr_blue;
private int r,g,b;
public MyScroll()
{
setTitle("Scrollbar");
setSize(500,500);
setLocation(100,100);
scr_red=new Scrollbar(Scrollbar.HORIZONTAL,0,45,0,300);
scr_green=new Scrollbar(Scrollbar.HORIZONTAL,0,45,0,300);
scr_blue=new Scrollbar(Scrollbar.HORIZONTAL,0,45,0,300);
scr_red.addAdjustmentListener(this);
scr_green.addAdjustmentListener(this);
scr_blue.addAdjustmentListener(this);
setLayout(null);
scr_red.setBounds(10,50,200,20);
scr_green.setBounds(10,80,200,20);
scr_blue.setBounds(10,110,200,20);
add(scr_red);
add(scr_green);
add(scr_blue);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
if(ae.getSource()==scr_red)
{
r=scr_red.getValue();
}
else if(ae.getSource()==scr_green)
{
g=scr_green.getValue();
}
else if(ae.getSource()==scr_blue)
{
b=scr_blue.getValue();
}
setBackground(new Color(r,g,b));
}
}
class ScrollDemo
{
public static void main(String []args)
{
new MyScroll().setVisible(true);
}
}
No comments:
Post a Comment