java - 如何使用同一个 ColorChooserButton 来执行两个不同的动作
问题描述
我正在使用 Swing 颜色选择器来更改绘制形状的颜色,问题是我想使用相同colorChooserwindow
且相同的按钮choose
来执行 2 个不同的操作,填充形状或更改形状线条颜色,但我无法区分哪个按钮是单击之前(fillColor
或lineColor
)我知道我应该向ColorChooserWindow
构造函数添加一些东西来告诉它正在选择哪种颜色但我无法弄清楚我尝试了一个ActionEvent
andgetSource()
方法但它不起作用
/** this is my constructor**/
/**
* Creates new form ColorPickerWindow
*/
public ColorPickerWindow(DrawingModel model) {
// save the model
myModel = model;
// window title
this.setTitle("Color Picker");
initComponents();
}
/** and this is the action performed method **/
private void chooseColorButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
DrawingWindow dw = new DrawingWindow(myModel);
myModel.setFillColor(jColorChooser.getColor());
dw.setVisible(true);
this.dispose();
}
解决方案
推荐阅读
- javascript - 表单验证和页面调用
- python - 将两个长度不等的 dfs 与匹配的索引子集合并
- bluetooth - 蓝牙和 BLE 配置文件
- css - 从 HTML 中隐藏给定的组合字符
- node.js - discord JS调度器只播放一半的歌曲
- java - 仅在Java中满足条件后如何启动计时器
- javascript - Vimeo App 允许最终用户通过 API 上传到所有者的帐户
- sql - 以下查询的时间戳转换
- javascript - Knex for posgres 使用默认模式创建与多个项目冲突的锁表
- simulation - 在 anylogic 中为 50% 的代理分配优先级