package colorjpane;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.colorchooser.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends JApplet {
private JColorChooser chooser = new JColorChooser();
private AbstractColorChooserPanel colorPanels[] =
new AbstractColorChooserPanel[] {
new ListPanel(),
};
private JButton button = new JButton("Show Color Chooser");
private JDialog dialog;
public void init() {
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.add(button, BorderLayout.CENTER);
chooser.addChooserPanel(colorPanels[0]);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(dialog == null)
dialog = JColorChooser.createDialog(
Test.this, // parent comp
"Pick A Color", // dialog title
false, // modality
chooser,
null, null);
dialog.setVisible(true);
}
});
}
}
class ListPanel extends AbstractColorChooserPanel
implements ListSelectionListener {
private JPanel labelPanel = new JPanel(),
listPanel = new JPanel();
private JList CList = new JList(), MList = new JList(),YList = new JList(),
KList=new JList();
private DefaultListModel CModel = new DefaultListModel(),
MModel = new DefaultListModel(),YModel = new DefaultListModel(),
KModel=new DefaultListModel();
private boolean isAdjusting = false;
ColorTranslate CMYKRGB=new ColorTranslate();
public void updateChooser() {
if( ! isAdjusting) {
isAdjusting = true;
Color color = getColorFromModel();
CMYKRGB.RGBtoCMYK(color);
CList.setSelectedIndex(CMYKRGB.C);
MList.setSelectedIndex(CMYKRGB.M);
YList.setSelectedIndex(CMYKRGB.Y);
KList.setSelectedIndex(CMYKRGB.K);
CList.ensureIndexIsVisible(CMYKRGB.C);
MList.ensureIndexIsVisible(CMYKRGB.M);
YList.ensureIndexIsVisible(CMYKRGB.Y);
KList.ensureIndexIsVisible(CMYKRGB.K);
isAdjusting = false;
}
}
protected void buildChooser() {
CList.setFixedCellWidth(50);
MList.setFixedCellWidth(50);
YList.setFixedCellWidth(50);
KList.setFixedCellWidth(50);
for(int i=0; i <=100; ++i) {
CModel.addElement(Integer.toString(i));
MModel.addElement(Integer.toString(i));
YModel.addElement(Integer.toString(i));
KModel.addElement(Integer.toString(i));
}
CList.setModel(CModel);
MList.setModel(MModel);
YList.setModel(YModel);
KList.setModel(KModel);
listPanel.setLayout(new GridLayout(0,4,10,0));
listPanel.add(new JScrollPane(CList));
listPanel.add(new JScrollPane(MList));
listPanel.add(new JScrollPane(YList));
listPanel.add(new JScrollPane(KList));
labelPanel.setLayout(new GridLayout(0,4,10,0));
labelPanel.add(new JLabel("C"));
labelPanel.add(new JLabel("M"));
labelPanel.add(new JLabel("Y"));
labelPanel.add(new JLabel("K"));
setLayout(new BorderLayout());
add(labelPanel, BorderLayout.NORTH);
add(listPanel, BorderLayout.CENTER);
CList.addListSelectionListener(this);
MList.addListSelectionListener(this);
YList.addListSelectionListener(this);
KList.addListSelectionListener(this);
}
public void valueChanged(ListSelectionEvent e) {
if(isAdjusting)
return;
isAdjusting=true;
CMYKRGB.C = CList.getSelectedIndex();
CMYKRGB.M = MList.getSelectedIndex();
CMYKRGB.Y = YList.getSelectedIndex();
CMYKRGB.K = KList.getSelectedIndex();
if((CMYKRGB.C<=100)&&(CMYKRGB.M<=100)&&(CMYKRGB.Y<=100)
&&(CMYKRGB.K<=100)&&(CMYKRGB.C>=0)&&(CMYKRGB.M>=0)&&(CMYKRGB.Y>=0)
&&(CMYKRGB.K>=0))
getColorSelectionModel().setSelectedColor(CMYKRGB.CMYKtoRGB());
isAdjusting=false;
}
public String getDisplayName() {
return "CMYK";
}
public Icon getSmallDisplayIcon() {
return null;
}
public Icon getLargeDisplayIcon() {
return null;
}
}
用Java语言实现RGB与CMYK色彩空间的转换
版权申诉
137 浏览量
2022-06-18
14:28:28
上传
评论
收藏 132KB RAR 举报
处处清欢
- 粉丝: 150
- 资源: 2471
最新资源
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
- 基于MIC+NE555光敏电阻的声光控电路Multisim仿真原理图
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈