我正在使用Swing颜色选择器更改绘制形状的颜色,问题是我想使用相同的colorChooserwindow
和相同的按钮choose
来执行2种不同的操作,要么填充形状或更改形状线的颜色,但是我无法区分之前单击过哪个按钮(fillColor
或lineColor
),我知道我应该向ColorChooserWindow
构造函数添加一些内容以告诉它哪种颜色被选中,但我无法弄清楚,我尝试了ActionEvent
和getSource()
方法,但无效
/** 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();
}