Program:
import java.awt.*;
import java.awt.event.*;
class ex6 extends Frame implements AdjustmentListener
{
Scrollbar s1,s2,s3;
Label l1;
Panel p;
int r,g,b;
ex6()
{
super("Colour Generator:Scroll bar example");
setLayout(null);
setSize(700,400);
setVisible(true);
l1=new Label("www.2K8618.blogspot.com");
l1.setBackground(Color.black);
l1.setForeground(Color.blue);
s1=new Scrollbar();
s2=new Scrollbar();
s3=new Scrollbar();
s1.setMaximum(255);
s2.setMaximum(255);
s3.setMaximum(255);
s1.setBounds(50,50,20,100);
add(s1);
s2.setBounds(50,160,20,100);
add(s2);
s3.setBounds(50,270,20,100);
add(s3);
p=new Panel();
p.setBounds(100,100,500,200);
add(p);
p.add(l1);
s1.addAdjustmentListener(this);
s2.addAdjustmentListener(this);
s3.addAdjustmentListener(this);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
if(s1==ae.getSource())
{
r=s1.getValue();
p.setBackground(new Color(r,g,b));
}
if(s2==ae.getSource())
{
g=s2.getValue();
p.setBackground(new Color(r,g,b));
}
if(s3==ae.getSource())
{
b=s3.getValue();
p.setBackground(new Color(r,g,b));
}
}
public static void main(String s[])
{
ex6 ob=new ex6();
}
}
Output:
nn@linuxmint ~/Desktop/java 7 $ javac ex6.java
nn@linuxmint ~/Desktop/java 7 $ java ex6
nn@linuxmint ~/Desktop/java 7 $
import java.awt.*;
import java.awt.event.*;
class ex6 extends Frame implements AdjustmentListener
{
Scrollbar s1,s2,s3;
Label l1;
Panel p;
int r,g,b;
ex6()
{
super("Colour Generator:Scroll bar example");
setLayout(null);
setSize(700,400);
setVisible(true);
l1=new Label("www.2K8618.blogspot.com");
l1.setBackground(Color.black);
l1.setForeground(Color.blue);
s1=new Scrollbar();
s2=new Scrollbar();
s3=new Scrollbar();
s1.setMaximum(255);
s2.setMaximum(255);
s3.setMaximum(255);
s1.setBounds(50,50,20,100);
add(s1);
s2.setBounds(50,160,20,100);
add(s2);
s3.setBounds(50,270,20,100);
add(s3);
p=new Panel();
p.setBounds(100,100,500,200);
add(p);
p.add(l1);
s1.addAdjustmentListener(this);
s2.addAdjustmentListener(this);
s3.addAdjustmentListener(this);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
if(s1==ae.getSource())
{
r=s1.getValue();
p.setBackground(new Color(r,g,b));
}
if(s2==ae.getSource())
{
g=s2.getValue();
p.setBackground(new Color(r,g,b));
}
if(s3==ae.getSource())
{
b=s3.getValue();
p.setBackground(new Color(r,g,b));
}
}
public static void main(String s[])
{
ex6 ob=new ex6();
}
}
nn@linuxmint ~/Desktop/java 7 $ javac ex6.java
nn@linuxmint ~/Desktop/java 7 $ java ex6
nn@linuxmint ~/Desktop/java 7 $
0 comments:
Post a Comment