//分解颜色
import javax.swing.*;
import javax.swing.colorchooser.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends JApplet
{ private JColorChooser chooser=new JColorChooser();
private JButton button=new JButton("颜色选择器") ;
private JDialog dialog;
//初始化程序
public void init()
{ Container contentPane=getContentPane();
contentPane.setLayout(new FlowLayout() );
contentPane.add(button,BorderLayout.CENTER);
chooser.setPreviewPanel(new PreviewPanel());
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(dialog==null)
dialog=JColorChooser.createDialog(
Test1.this,//parent comp
"pick A color",
false,
chooser,
null,
null);
dialog.setVisible(true);
}
});
}
class PreviewPanel extends JPanel
{ public PreviewPanel()
{
setPreferredSize(new Dimension(0,100) );
setBorder(BorderFactory.createRaisedBevelBorder());
}
public void painTComonent(Graphics g){
Dimension size=getSize();
g.setColor(getForeground()) ;
g.fillRect(0,0,size.width ,size.height ) ;
}
}
}
阅读(1816) | 评论(0) | 转发(0) |