Commit a3ee7ea7 authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch14] Single ActionListener with if statement, nasty.

parent 7ba4f7b1
Loading
Loading
Loading
Loading
+17 −5
Changes for src/main/java/ch14/MyGui.java: 17 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -4,15 +4,27 @@ import javax.swing.*;
import java.awt.event.*;

class MyGui implements ActionListener {
  private JButton colorButton;
  private JButton labelButton;
  private JFrame frame;
  private JLabel label;
  // lots of code here and then:
  // declare a bunch of instance variables here

  public void go() {
    // build gui
    colorButton = new JButton();
    labelButton = new JButton();
    colorButton.addActionListener(this);
    labelButton.addActionListener(this);
    // more gui code here ...
  }

  public void actionPerformed(ActionEvent event) {
    if (event.getSource() == colorButton) {
      frame.repaint();
    } else {
      label.setText("That hurt!");
    }

//  public void actionPerformed(ActionEvent event) {
//    label.setText("That hurt!");
//  }
  }
}