Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionEvent Problem

 
Jeremy Brehmer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package App.java;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.awt.*;
import java.awt.event.*;
public class App extends Frame implements
WindowListener, ActionListener {
Button b;
public static void main(String[] args) {
App myWindow = new App("My first window");
myWindow.setVisible(true);
}
public App(String title) {
super(title);
setLayout(new FlowLayout());
addWindowListener(this);
b = new Button("Click me");
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
b.setLabel("Ouch!!"|"Ow!!");
}
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
public void windowOpened(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
}
I cann't seem to figure out how to switch the buttons name from "Ouch!!" to "Ow!!" everytime I click the button..
1st click Ouch!! works
2nd click Ow!! not sure how to code...
3rd click Ouch!! it goes back to Ouch!!
I tried a few ideas but i cann't seem to figure it out..
Can someone please help me out..
Thanks
 
wayne hitchcock
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if(b.getLabel().equals("Ouch!!"))
b.setLabel("Ow!!);
else
b.setLabel("Ouch!!");
 
Jeremy Brehmer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thank you very much wayne...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic