import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class sliders extends JFrame
implements ChangeListener
{
Container c;
JLabel l1,l2,l3;
JSlider s1,s2,s3;
JTextField t1;
public sliders()
{
l1=new JLabel("Red");
l2=new
JLabel("Green");
l3=new
JLabel("Blue");
s1=new JSlider();
s2=new JSlider();
s3=new JSlider();
setSize(250,300);
setDefaultCloseOperation(0);
c=getContentPane();
c.setLayout(new FlowLayout());
s1.setMinimum(0);
s2.setMinimum(0);
s3.setMinimum(0);
s1.setMaximum(255);
s2.setMaximum(255);
s3.setMaximum(255);
s1.setMajorTickSpacing(50);
s2.setMajorTickSpacing(50);
s3.setMajorTickSpacing(50);
s1.setPaintTicks(true);
s2.setPaintTicks(true);
s3.setPaintTicks(true);
s1.setPaintLabels(true);
s2.setPaintLabels(true);
s3.setPaintLabels(true);
c.add(l1); c.add(s1);
c.add(l2); c.add(s2);
c.add(l3); c.add(s3);
s1.addChangeListener(this);
s2.addChangeListener(this);
s3.addChangeListener(this);
}
public void stateChanged(ChangeEvent e)
{
int r,g,b;
Color c1;
r=s1.getValue();
g=s2.getValue();
b=s3.getValue();
c1=new Color(r,g,b);
c.setBackground(c1);
}
public static void main(String args[])
{
color m=new color();
m.setVisible(true);
}
}
No comments:
Post a Comment