Loading src/main/java/ch14/MyGui.java +13 −15 Changes for src/main/java/ch14/MyGui.java: 13 added lines, 15 removed lines. Original line number Diff line number Diff line Loading @@ -3,28 +3,26 @@ package ch14; import javax.swing.*; import java.awt.event.*; class MyGui implements ActionListener { private JButton colorButton; private JButton labelButton; class MyGui { private JFrame frame; private JLabel label; // 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 ... void gui() { // code to instantiate the two listeners and register one // with the color button and the other with the label button } } class ColorButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { if (event.getSource() == colorButton) { frame.repaint(); } else { label.setText("That hurt!"); // frame.repaint(); } } class LabelButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { // label.setText("That hurt!"); } } Loading
src/main/java/ch14/MyGui.java +13 −15 Changes for src/main/java/ch14/MyGui.java: 13 added lines, 15 removed lines. Original line number Diff line number Diff line Loading @@ -3,28 +3,26 @@ package ch14; import javax.swing.*; import java.awt.event.*; class MyGui implements ActionListener { private JButton colorButton; private JButton labelButton; class MyGui { private JFrame frame; private JLabel label; // 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 ... void gui() { // code to instantiate the two listeners and register one // with the color button and the other with the label button } } class ColorButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { if (event.getSource() == colorButton) { frame.repaint(); } else { label.setText("That hurt!"); // frame.repaint(); } } class LabelButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { // label.setText("That hurt!"); } }