21 Şubat 2016 Pazar

Java RgbColor

Uğraşma sonucu Allahın lutfuyla Güzel bir Uygulama oldu.
Bu uygulama asıl amac renklerin butun tonlarını bir panele verebilmekti.Ve sonunda başarabildik.
public class ColorFrame extends JFrame implements ChangeListener {

    JPanel renkPane;
    JPanel rgbPane;
    JSlider s1;
    JSlider s2;
    JSlider s3;
    int r, g, b;

    public ColorFrame(String title) {
        super(title);
        renkPane = new JPanel();
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        s1 = new JSlider(0, 255);
        s1.setPaintTicks(true);
        s1.setForeground(Color.red);
        s1.setMinorTickSpacing(5);
        s1.setMajorTickSpacing(5);
        s2 = new JSlider(0, 255);
        s2.setForeground(Color.GREEN);
        s2.setPaintTicks(true);
        s2.setMinorTickSpacing(5);
        s2.setMajorTickSpacing(5);
        s3 = new JSlider(0, 255);
        s3.setPaintTicks(true);
        s3.setForeground(Color.BLUE);
        s3.setMinorTickSpacing(5);
        s3.setMajorTickSpacing(5);
        renkPane = new JPanel();
        rgbPane = new JPanel();
        s1.addChangeListener(this);
        s2.addChangeListener(this);
        s3.addChangeListener(this);
        renkPane.setSize(100, 100);
        renkPane.setLayout(new BoxLayout(renkPane, BoxLayout.Y_AXIS));
        renkPane.setBorder(new EtchedBorder(Color.lightGray, Color.RED));
        rgbPane.setBorder(new EtchedBorder(Color.lightGray, Color.RED));
        this.setSize(500, 500);
        renkPane.add(s1);
        renkPane.add(s2);
        renkPane.add(s3);
        renkPane.add(rgbPane);
        this.add(renkPane);
        this.setVisible(true);
    }

    public static void main(String[] args) {
        ColorFrame fr = new ColorFrame("Color Frame");
    }

    @Override
    public void stateChanged(ChangeEvent e) {
        if (e.getSource() == s1) {
            r = (int) s1.getValue();
            g = (int) s2.getValue();
            b = (int) s3.getValue();
            rgbPane.setBackground(new Color(r, g, b));
            repaint();
        } else if (e.getSource() == s2) {
            r = (int) s1.getValue();
            g = (int) s2.getValue();
            b = (int) s3.getValue();
            rgbPane.setBackground(new Color(r, g, b));
            repaint();
        } else {
            r = (int) s1.getValue();
            g = (int) s2.getValue();
            b = (int) s3.getValue();
            rgbPane.setBackground(new Color(r, g, b));
            repaint();
        }
    }
}
Ekran cıktısı :

Hiç yorum yok:

Yorum Gönder

Lütfen yorumlarınızı iletiniz...