how to use the same ColorChooserButton to perform two different actions

43 views Asked by At

I am using a Swing color picker to change the color of drawn shapes, the problem is I want to use the same colorChooserwindow and same button choose to perform 2 different actions, either filling the shape or changing the shape line color but I cannot differentiate which button was clicked before (fillColor or lineColor) I know that I should add something to the ColorChooserWindow constructor to tell it which kind of color is being chosen but I cannot figure it out I tried an ActionEvent and getSource() method but it doesn't work

/** 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

There are 0 answers