NellyIvanova29

Scrollbar

Mar 25th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.71 KB | None | 0 0
  1. package scroll;
  2.  
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JFrame;
  6.  
  7. import java.awt.event.AdjustmentEvent;
  8. import java.awt.FlowLayout;
  9. import java.awt.Color;
  10. import javax.swing.JButton;
  11. import javax.swing.JScrollBar;
  12. import javax.swing.JLabel;
  13. import javax.swing.JFrame;
  14. import java.awt.event.AdjustmentListener;
  15.  
  16. public class scroll {
  17.  
  18.     private JFrame frmScrollbarColourChange;
  19.  
  20.     /**
  21.      * Launch the application.
  22.      */
  23.     public static void main(String[] args) {
  24.         EventQueue.invokeLater(new Runnable() {
  25.             public void run() {
  26.                 try {
  27.                     scroll window = new scroll();
  28.                     window.frmScrollbarColourChange.setVisible(true);
  29.                 } catch (Exception e) {
  30.                     e.printStackTrace();
  31.                 }
  32.             }
  33.         });
  34.     }
  35.  
  36.     /**
  37.      * Create the application.
  38.      */
  39.     public scroll() {
  40.         initialize();
  41.     }
  42.  
  43.     /**
  44.      * Initialize the contents of the frame.
  45.      */
  46.     private void initialize() {
  47.         frmScrollbarColourChange = new JFrame();
  48.         frmScrollbarColourChange.setTitle("Scrollbar colour change");
  49.         frmScrollbarColourChange.setBounds(100, 100, 653, 358);
  50.         frmScrollbarColourChange.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  51.         frmScrollbarColourChange.getContentPane().setLayout(null);
  52.        
  53.         JLabel lblNewLabel = new JLabel("      ");
  54.         lblNewLabel.setBounds(126, 52, 368, 81);
  55.         frmScrollbarColourChange.getContentPane().add(lblNewLabel);
  56.        
  57.         JScrollBar r = new JScrollBar();
  58.        
  59.         r.setOrientation(JScrollBar.HORIZONTAL);
  60.         r.setMaximum(255);
  61.         r.setBounds(226, 164, 268, 17);
  62.         frmScrollbarColourChange.getContentPane().add(r);
  63.        
  64.         JScrollBar g = new JScrollBar();
  65.        
  66.         g.setOrientation(JScrollBar.HORIZONTAL);
  67.         g.setMaximum(255);
  68.         g.setBounds(226, 207, 268, 17);
  69.         frmScrollbarColourChange.getContentPane().add(g);
  70.        
  71.         JScrollBar b = new JScrollBar();
  72.        
  73.         b.setMaximum(255);
  74.         b.setOrientation(JScrollBar.HORIZONTAL);
  75.         b.setBounds(226, 249, 268, 17);
  76.         frmScrollbarColourChange.getContentPane().add(b);
  77.        
  78.         JLabel lblNewLabel_1 = new JLabel("Red");
  79.         lblNewLabel_1.setBounds(143, 167, 46, 14);
  80.         frmScrollbarColourChange.getContentPane().add(lblNewLabel_1);
  81.        
  82.         JLabel lblNewLabel_2 = new JLabel("Green");
  83.         lblNewLabel_2.setBounds(143, 207, 46, 14);
  84.         frmScrollbarColourChange.getContentPane().add(lblNewLabel_2);
  85.        
  86.         JLabel lblNewLabel_3 = new JLabel("Blue");
  87.         lblNewLabel_3.setBounds(143, 252, 46, 14);
  88.         frmScrollbarColourChange.getContentPane().add(lblNewLabel_3);
  89.        
  90.         r.addAdjustmentListener(new AdjustmentListener() {
  91.             public void adjustmentValueChanged(AdjustmentEvent e) {
  92.                 lblNewLabel.setBackground(new Color(r.getValue(),g.getValue(),b.getValue()));
  93.                 lblNewLabel.setOpaque(true);
  94.             }
  95.         });    
  96.         g.addAdjustmentListener(new AdjustmentListener() {
  97.             public void adjustmentValueChanged(AdjustmentEvent e) {
  98.                 lblNewLabel.setBackground(new Color(r.getValue(),g.getValue(),b.getValue()));
  99.                 lblNewLabel.setOpaque(true);
  100.             }
  101.         });
  102.         b.addAdjustmentListener(new AdjustmentListener() {
  103.             public void adjustmentValueChanged(AdjustmentEvent e) {
  104.                lblNewLabel.setBackground(new Color(r.getValue(),g.getValue(),b.getValue()));
  105.                lblNewLabel.setOpaque(true);
  106.             }
  107.         });
  108.  
  109.      
  110.        
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment