如何使用同一个ColorChooserButton来执行两个不同的操作

时间:2019-05-02 21:30:42

标签: java swing user-interface jcolorchooser

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

/** 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();
}

0 个答案:

没有答案
相关问题