1.颜色对话框
可以用函数:public static Color show Dialog(Component component,String title,Color initialColor)
创建一个颜色对话框。
component指定对话框可见位置;title指定对话框标题;initialColor指定对话框返回的初始颜色,也就是运行效果的示例颜色。
下面是实例:
public class Example9_19 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WindowColor win=new WindowColor();
win.setTitle("颜色对话框");
win.setBounds(500,250,200,300);
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class WindowColor extends JFrame implements ActionListener{
JButton button;
WindowColor(){
button=new JButton("打开颜色对话框");
button.addActionListener(this);
setLayout(new FlowLayout());
add(button);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
Color newColor=JColorChooser.showDialog(this,"调色板",getContentPane().getBackground());
if(newColor!=null){
getContentPane().setBackground(newColor);
}
}
}