首页 > 解决方案 > 如何使用同一个 ColorChooserButton 来执行两个不同的动作

问题描述

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

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

标签: javaswinguser-interfacejcolorchooser

解决方案


推荐阅读