source code name: AdjustmentEventDemo.java
import java.awt.*;
import java.awt.event.*;
class AdjustmentEventDemo extends Frame implements AdjustmentListener
{
Color col=Color.green;
Scrollbar sb1,sb2,sb3;
public AdjustmentEventDemo()
{
BorderLayout bl=new BorderLayout();
setLayout(bl);
Panel p=new Panel();
GridLayout gl=new GridLayout();
p.setForeground(Color.pink);
p.setLayout(gl);
sb1=new Scrollbar(Scrollbar.VERTICAL,50,10,1,255);
sb2=new Scrollbar(Scrollbar.VERTICAL,50,10,1,255);
sb3=new Scrollbar(Scrollbar.VERTICAL,50,10,1,255);
p.add(sb1);
p.add(sb2);
p.add(sb3);
add(p,BorderLayout.EAST);
sb1.addAdjustmentListener(this);
sb2.addAdjustmentListener(this);
sb3.addAdjustmentListener(this);
}
public void adjustmentValueChanged(AdjustmentEvent ade)
{
int r,g,b;
r=sb1.getValue();
g=sb2.getValue();
b=sb3.getValue();
System.out.println("r: "+r+" g: "+g+" b: "+b);
col=new Color(r,g,b);
repaint();
}
public void paint(Graphics g)
{
g.setColor(col);
g.fillOval(50,200,100,100);
}
public static void main(String[] args)
{
AdjustmentEventDemo f=new AdjustmentEventDemo();
f.setTitle("Adjustment Event Program");
f.setSize(400,500);
f.setVisible(true);
}
}
output:
0 Comments
Post a Comment