源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

java使用颜色选择器示例分享

  • 时间:2022-03-09 14:09 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:java使用颜色选择器示例分享
[u]复制代码[/u] 代码如下:
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);     }   } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部