Setting JColorChoose to a button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tommyny04
    New Member
    • Sep 2007
    • 6

    #1

    Setting JColorChoose to a button

    Hi all, I'm trying to write code so that when a button is clicked, a JColorChooser pops up. For some reason, the code I wrote i snot working and I can't figure out the reason. Any help would be greatly appreciated thanks.

    [CODE]

    private static JButton changeColorButt on = new JButton("Change Color");
    private static JButton loadButton = new JButton("Open") ;

    public void actionPerformed (ActionEvent ae) {
    String command = ae.getActionCom mand();

    if (command == "Open") {
    JFileChooser chooser = new JFileChooser();
    chooser.showOpe nDialog(loadBut ton);
    file = chooser.getSele ctedFile();
    loadPic(file);
    repaint();
    }
    else if (command == "Change Color") {
    JColorChooser colors = new JColorChooser() ;
    colors.setPrevi ewPanel(changeC olorButton);

    }
    }

    [\CODE]
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by tommyny04
    if (command == "Open") {
    You can't compare Strings like that; use the equals() method instead. Read the
    API documentation for the String class.

    kind regards,

    Jos

    Comment

    Working...