Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class Farby extends JFrame implements AdjustmentListener
  6. {
  7. private JScrollBar sb1, sb2, sb3;
  8. private JLabel l1;
  9. private JButton b1;
  10. private Color c;
  11.  
  12. public void adjustmentValueChanged(AdjustmentEvent e){
  13. c = new Color(sb1.getValue(), sb2.getValue(), sb3.getValue());
  14. b1.setBackground(c);
  15. l1.setText("Barva ["+sb1.getValue()+","+sb2.getValue()+","+sb3.getValue()+"]");
  16. }
  17.  
  18. public Farby(){
  19. super("Barvičky!");
  20. setDefaultCloseOperation(EXIT_ON_CLOSE);
  21. setVisible(true);
  22.  
  23. setLayout(new BorderLayout());
  24. sb1 = new JScrollBar(JScrollBar.HORIZONTAL,0,1,0,256);
  25. sb1.addAdjustmentListener(this);
  26. add(sb1, BorderLayout.NORTH);
  27.  
  28. sb2 = new JScrollBar(JScrollBar.VERTICAL,0,1,0,256);
  29. sb2.addAdjustmentListener(this);
  30. add(sb2, BorderLayout.WEST);
  31.  
  32. sb3 = new JScrollBar(JScrollBar.HORIZONTAL,0,1,0,256);
  33. sb3.addAdjustmentListener(this);
  34. add(sb3, BorderLayout.SOUTH);
  35.  
  36. l1 = new JLabel("Barva ["+sb1.getValue()+","+sb2.getValue()+","+sb3.getValue()+"]");
  37. l1.setHorizontalAlignment(JLabel.CENTER);
  38. add(l1, BorderLayout.CENTER);
  39. b1 = new JButton(" ");
  40. add(b1, BorderLayout.EAST);
  41.  
  42.  
  43. pack();
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement