package javaapplication4;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.math.*;
import java.lang.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class JavaApplication4 extends JFrame
{
JSlider red,green,blue;
JLabel r,g,b;
JPanel colorpane,slider,label;
public JavaApplication4()
{
red= new JSlider(JSlider.HORIZONTAL,0,255,0);
green= new JSlider(JSlider.HORIZONTAL,0,255,0);
blue= new JSlider(JSlider.HORIZONTAL,0,255,0);
r=new JLabel("Red");
g =new JLabel("Green");
b = new JLabel("Blue");
slider = new JPanel();
colorpane=new JPanel();
label =new JPanel();
Container pane = this.getContentPane();
pane.setLayout(new GridLayout(1,3,3,3));
pane.add(slider);
pane.add(label);
pane.add(colorpane);
slider.setLayout(new GridLayout(3,1,0,0));
slider.add(red);
slider.add(green);
slider.add(blue);
label.setLayout(new GridLayout(3,1,1,1));
label.add(r);
label.add(g);
label.add(b);
event e = new event();
red.addChangeListener(e);
green.addChangeListener(e);
blue.addChangeListener(e);
}
public class event implements ChangeListener
{
public void stateChanged(ChangeEvent e)
{
int rr = red.getValue();
int gg= green.getValue();
int bb = blue.getValue();
r.setText("Red"+ rr);
g.setText("Green"+ gg);
b.setText("Blue"+ bb);
colorpane.setBackground(new Color(rr,gg,bb));
}
}
public static void main(String[] args) {
JavaApplication4 gui = new JavaApplication4();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setTitle("Change Colour");
gui.setVisible(true);
gui.setSize(500, 500);
}
}
ConversionConversion EmoticonEmoticon