ColorChooser

 Java JcolorChooser

 

 

ColorChooser nesnesinin messageDialog nesnesinden bir farki yok aslinda.

Bir Color nesnesi olusturuyoruz ve ColorChooser ile seçtigimiz rengi o Color degiskenine atiyoruz.

 .

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

 

import javax.swing.*;

 

public class Renkler extends JFrame{

                JButton btn;

                Color renk = (Color.white);

                JPanel panel;               

                public Renkler(){

                               super("java JColorChooser örnek");

                               panel = new JPanel();

                               panel.setBackground(renk);

                               btn = new JButton("Renk seç");

                               btn.addActionListener(

                               new ActionListener(){

                                               public void actionPerformed(ActionEvent e){

                                                          renk = JColorChooser.showDialog(null, "Bir renk seçiniz", renk);

                                                               if(renk==null) //eger bir renk seçilmediyse

                                                                              renk = (Color.white);

                                                              

                                                               panel.setBackground(renk);

                                               }

                               }

                               );

                              

                               add(panel, BorderLayout.CENTER);

                               add(btn, BorderLayout.SOUTH);  

                }               

                public static void main(String[] arg){

                               Renkler r = new Renkler();

                               r.setSize(300,300);

                               r.setDefaultCloseOperation(r.EXIT_ON_CLOSE);

                               r.setVisible(true);

                }           

}

 

Tags:

2 thoughts on “ColorChooser

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir