Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication16;
- //import static com.sun.java.accessibility.util.SwingEventMonitor.addChangeListener;
- import java.util.*;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseListener;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- public class JavaApplication16 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Okno o = new Okno("ABC", 100, 200, 500, 500);
- }
- }
- //------------------------------------------------------------------------------
- class Okno extends JFrame
- {
- private MojPanel centr = new MojPanel();
- JSlider R = new JSlider(0, 255, 100), G = new JSlider(0, 255, 100), B = new JSlider(0, 255, 100);
- private Container tlo;
- int bn = 100, rn = 100, gn = 100;
- public Okno(String atyt, int ax0, int ay0, int aszer, int awys)
- {
- super(atyt);
- setBounds(ax0, ay0, aszer, awys);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- tlo = getContentPane();
- // tlo.setBackground(new Color(100, 100, 100));
- budujUI();
- setVisible(true);
- }
- private void budujUI()
- {
- tlo.setLayout( new BorderLayout());
- JPanel gorny = new JPanel();
- gorny.setBackground(Color.blue);
- //gorny.setLayout(new GridLayout(1,4));
- // gorny.setLayout(new FlowLayout(FlowLayout.RIGHT ,10, 5));
- tlo.add(BorderLayout.NORTH, gorny);
- tlo.add(BorderLayout.CENTER, centr);
- //MojPanel cent = new MojPanel();
- //tlo.add(BorderLayout.CENTER, cent);
- JButton koniec = new JButton("Koniec");
- koniec.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent ae) {
- dispose();
- }
- });
- gorny.add(koniec);
- R.addChangeListener(new KliknietoSlider());
- gorny.add(R);
- G.addChangeListener(new KliknietoSlider());
- gorny.add(G);
- B.addChangeListener(new KliknietoSlider());
- gorny.add(B);
- }
- class KliknietoSlider implements ChangeListener
- {
- @Override
- public void stateChanged(ChangeEvent ce) {
- centr.setKolorKota(new Color(R.getValue(), G.getValue(), B.getValue()));
- }
- }
- }
- //------------------------------------------------------------------------------
- class MojPanel extends JPanel
- {
- private Color k = new Color(100, 100, 100);
- public MojPanel()
- {
- super();
- }
- @Override
- public void paintComponent(Graphics g)
- {
- super.paintComponent(g);
- int szer = getWidth();
- int wys = getHeight();
- g.setColor(k);
- g.fillOval(szer/4, wys/4, szer/2, wys/2);
- // g.setColor(k);
- g.drawOval(szer/4, wys/4, szer/2, wys/2);
- }
- public void setKolorKota( Color ak)
- {
- k = ak;
- repaint();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement