java使用颜色选择器示例分享
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);
}
}
}
上一篇: jdbc连接sqlserver数据库示例
下一篇: java实现八皇后问题示例分享