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);
}
}
}
相關(guān)文章
JPA自定義對(duì)象接收查詢(xún)結(jié)果集操作
這篇文章主要介紹了JPA自定義對(duì)象接收查詢(xún)結(jié)果集操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-01-01
Spring ApplicationContext上下文核心容器深入探究
ApplicationContext是Spring應(yīng)用程序中的中央接口,由于繼承了多個(gè)組件,使得ApplicationContext擁有了許多Spring的核心功能,如獲取bean組件,注冊(cè)監(jiān)聽(tīng)事件,加載資源文件等2023-01-01
Java并發(fā)編程變量可見(jiàn)性避免指令重排使用詳解
這篇文章主要為大家介紹了Java并發(fā)編程變量可見(jiàn)性避免指令重排使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
Java?DelayQueue實(shí)現(xiàn)任務(wù)延時(shí)示例講解
DelayQueue是一個(gè)無(wú)界的BlockingQueue的實(shí)現(xiàn)類(lèi),用于放置實(shí)現(xiàn)了Delayed接口的對(duì)象,其中的對(duì)象只能在其到期時(shí)才能從隊(duì)列中取走。本文就來(lái)利用DelayQueue實(shí)現(xiàn)延時(shí)任務(wù),感興趣的可以了解一下2022-09-09

