Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class Farby extends JFrame implements AdjustmentListener
- {
- private JScrollBar sb1, sb2, sb3;
- private JLabel l1;
- private JButton b1;
- private Color c;
- public void adjustmentValueChanged(AdjustmentEvent e){
- c = new Color(sb1.getValue(), sb2.getValue(), sb3.getValue());
- b1.setBackground(c);
- l1.setText("Barva ["+sb1.getValue()+","+sb2.getValue()+","+sb3.getValue()+"]");
- }
- public Farby(){
- super("Barvičky!");
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setVisible(true);
- setLayout(new BorderLayout());
- sb1 = new JScrollBar(JScrollBar.HORIZONTAL,0,1,0,256);
- sb1.addAdjustmentListener(this);
- add(sb1, BorderLayout.NORTH);
- sb2 = new JScrollBar(JScrollBar.VERTICAL,0,1,0,256);
- sb2.addAdjustmentListener(this);
- add(sb2, BorderLayout.WEST);
- sb3 = new JScrollBar(JScrollBar.HORIZONTAL,0,1,0,256);
- sb3.addAdjustmentListener(this);
- add(sb3, BorderLayout.SOUTH);
- l1 = new JLabel("Barva ["+sb1.getValue()+","+sb2.getValue()+","+sb3.getValue()+"]");
- l1.setHorizontalAlignment(JLabel.CENTER);
- add(l1, BorderLayout.CENTER);
- b1 = new JButton(" ");
- add(b1, BorderLayout.EAST);
- pack();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement