java使用颜色选择器示例分享
2014-03-07 16:13
771 查看
package com.liuxing.test;import java.awt.Color;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JColorChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;public class ColorChooser extends JFrame { private JLabel sampleText = new JLabel("Label"); private JButton chooseButton = new JButton("Choose Color");
public static void main(String[] args) { new ColorChooser(); }
public ColorChooser() { this.setSize(300, 100); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel1 = new JPanel(); sampleText.setBackground(null); panel1.add(sampleText);
chooseButton.addActionListener(new ButtonListener()); panel1.add(chooseButton);
this.add(panel1); this.setVisible(true); }
private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { Color c = JColorChooser.showDialog(null, "Choose a Color", sampleText.getForeground()); if (c != null) sampleText.setForeground(c); } }}
相关文章推荐
- java使用des加密解密示例分享
- java使用listIterator逆序arraylist示例分享
- java使用ftp上传文件示例分享
- java使用泛型实现栈结构示例分享
- java使用iterator遍历指定目录示例分享
- java使用jdbc操作数据库示例分享
- java反射使用示例分享
- java使用listIterator逆序arraylist示例分享
- java比较器comparator使用示例分享
- java使用listIterator逆序arraylist示例分享
- Java分页工具类及其使用(示例分享)
- java使用swt显示图片示例分享
- java的nio的使用示例分享
- java使用rmi传输大文件示例分享
- java使用xpath解析xml示例分享
- java Preferences持久化使用示例
- 在java中使用dom4j解析xml(示例代码)
- asp.net微软图表控件使用示例代码分享
- Java操作MongoDB数据库示例分享
- 运行失败的 疯狂java讲义示例 使用Annotation示例