调色板的调用

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 JColorChooserDemo extends JFrame implements ActionListener{
public static void main(String[] args) {
JColorChooserDemo jcc=new JColorChooserDemo();
jcc.setTitle("颜料板");
jcc.setBounds(80,90,200,300);
jcc.setVisible(true);
}
JColorChooserDemo(){
JButton button=new JButton("打开颜料板");
button.addActionListener(this);
setLayout(new FlowLayout());
add(button);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
public void actionPerformed(ActionEvent e) {
Color newcolor=JColorChooser.showDialog(this,"调色板",getContentPane().getBackground());
if(newcolor!=null){
getContentPane().setBackground(newcolor);//JFrame类里面只能由内容面板来设定颜色
}

}

}

猜你喜欢

转载自qq-24665727.iteye.com/blog/2259775