import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RedGreenBlue extends JFrame implements AdjustmentListener{
private JScrollBar jsr,jsb,jsg;
private JLabel lr,lg,lb,lnr,lnb,lng;
Container con=getContentPane();
public RedGreenBlue() {
con.setLayout(null);
lr=new JLabel("Red"); lr.setBounds(20,30,40,20); con.add(lr);
lg=new JLabel("Green"); lg.setBounds(20,60,40,20); con.add(lg);
lb=new JLabel("Blue"); lb.setBounds(20,90,40,20); con.add(lb);
jsr=new JScrollBar(SwingConstants.HORIZONTAL,0,10,0,255);
jsr.setBounds(65,30,370,20); con.add(jsr);
jsg=new JScrollBar(SwingConstants.HORIZONTAL,0,10,0,255);
jsg.setBounds(65,60,370,20); con.add(jsg);
jsb=new JScrollBar(SwingConstants.HORIZONTAL,0,10,0,255);
jsb.setBounds(65,90,370,20); con.add(jsb);
lnr=new JLabel("255"); lnr.setBounds(450,30,40,20); con.add(lnr);
lng=new JLabel("255"); lng.setBounds(450,60,40,20); con.add(lng);
lnb=new JLabel("255"); lnb.setBounds(450,90,40,20); con.add(lnb);
jsr.addAdjustmentListener(this);
jsg.addAdjustmentListener(this);
jsb.addAdjustmentListener(this);
setSize(500,400);
setVisible(true);
setResizable(false);
setTitle("RGB");
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new RedGreenBlue();
}
public void adjustmentValueChanged(AdjustmentEvent e){
int r=jsr.getValue();
int g=jsg.getValue();
int b=jsb.getValue();
lnr.setText(String.valueOf(r));
lng.setText(String.valueOf(g));
lnb.setText(String.valueOf(b));
Color c=new Color(r,g,b);
con.setBackground(c);
}
}
Download source code *.java
http://www.mediafire.com/download/bfhqsag5j8yevl8/ChangeColorBackGroundJScroll.java
Blogger Comment
Facebook Comment