Color chooser dialog penceresi oluşturma


package colorChooser;


import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;

public class renkSecici {

 private static void guiGoster() {


  final JFrame frame = new JFrame("Renk Paneli");
  frame.setSize(250, 250);
  frame.setVisible(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.getContentPane().setLayout(new FlowLayout());

  JButton button = new JButton("Renk Seç");
  button.setSize(50, 50);

  button.addActionListener(new ActionListener() {
   @Override
   public void actionPerformed(ActionEvent e) {
    Color color = JColorChooser.showDialog(frame, "Bir Renk Seçiniz", Color.pink);
    System.out.println("Seçilen Renk:" + color);
   }
  });

  frame.getContentPane().add(button);

 }

 
 public static void main(String[] args) {

  javax.swing.SwingUtilities.invokeLater(new Runnable() {

   public void run() { guiGoster(); }

  });
    }

}

Hiç yorum yok :