SHARE
TWEET

Untitled

a guest Nov 21st, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import javax.swing.*;
  2. import javax.swing.border.Border;
  3. import javax.swing.event.ChangeEvent;
  4. import javax.swing.event.ChangeListener;
  5.  
  6. import java.awt.*;
  7. import java.awt.event.*;
  8.  
  9. public class Okno3 {
  10.     public static void main(String[] args) {
  11.         Okno okno = new Okno("Okienko", 100, 100, 800, 600);
  12.         okno.setVisible(true);
  13.     }
  14.  
  15. }
  16.  
  17. class Okno extends JFrame {
  18.     private Container background;
  19.     private JPanel center;
  20.     private JSlider R, G, B;
  21.  
  22.     public Okno(String txt, int x, int y, int szer, int wys) {
  23.         super(txt);
  24.         setBounds(x, y, szer, wys);
  25.         background = getContentPane();
  26.         buildUI();
  27.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28.     }
  29.  
  30.     private void buildUI() {
  31.         JPanel top = new JPanel();
  32.         top.setBackground(Color.gray);
  33.         background.add(top, BorderLayout.NORTH);
  34.  
  35.         center = new JPanel();
  36.         background.add(center, BorderLayout.CENTER);
  37.  
  38.         // Red slider
  39.         R = new JSlider(0, 255, 0);
  40.         R.setBackground(Color.red);
  41.         R.addChangeListener(new ChangeColor());
  42.  
  43.         top.add(R);
  44.        
  45.         G = new JSlider(0, 255, 0);
  46.         G.setBackground(Color.green);
  47.         G.addChangeListener(new ChangeColor());
  48.  
  49.         top.add(G);
  50.  
  51.  
  52.         B = new JSlider(0, 255, 0);
  53.         B.setBackground(Color.blue);
  54.         B.addChangeListener(new ChangeColor());
  55.         top.add(B);
  56.  
  57.  
  58.         // END_BUTTON TOP
  59.         JButton end_button = new JButton("Koniec");
  60.         end_button.addActionListener(new ActionListener(){
  61.             @Override
  62.             public void actionPerformed(ActionEvent e){
  63.                 dispose();
  64.             }
  65.         });
  66.         top.add(end_button);
  67.     }  
  68.  
  69.     class ChangeColor implements ChangeListener{
  70.         @Override
  71.             public void stateChanged(ChangeEvent e) {
  72.                 int rr = R.getValue();
  73.                 int gg = G.getValue();
  74.                 int bb = B.getValue();
  75.                 center.setBackground(new Color(rr,gg,bb));
  76.             }
  77.     }
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top