943,840 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 15813
  • Java RSS
Jun 25th, 2004
0

Action listeners

Expand Post »
hi everyone.Can anione please tell me how can i create an action listener on a button in a java application.I know how to create one on an applet but somehow cant seem to do like wise on an application.Please help!.. :o
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
teritori is offline Offline
11 posts
since Jun 2004
Jul 1st, 2004
0

Re: Action listeners

Im quite sure there is no difference between an applet and an aplication.

Java Syntax (Toggle Plain Text)
  1. import java.awt.event.*;
  2. import javax.swing.*;
  3. import java.awt.*;
  4.  
  5. public class MyFrame extends JFrame implements ActionListener {
  6.  
  7. Button button = new Button("Push me!");
  8.  
  9. public MyFrame() {
  10.  
  11. super("MyFrame");
  12. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  13. setSize(200, 100);
  14. button.addActionListener(this);
  15. getContentPane().setLayout(new BorderLayout());
  16. getContentPane().add("Center", button);
  17. setVisible(true);
  18. }
  19.  
  20. public final void actionPerformed(ActionEvent e) {
  21.  
  22. if (e.getActionCommand().equals(button.getActionCommand())) {
  23. JOptionPane.showMessageDialog(this, "Hey, you pushed me!", "Button says: ", JOptionPane.PLAIN_MESSAGE);
  24. }
  25. }
  26.  
  27. public static void main(String[] args) {
  28.  
  29. MyFrame mf = new MyFrame();
  30. }
  31. }
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Pogo is offline Offline
4 posts
since Jul 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Do I have to sign my applet to run it with fullscreen?
Next Thread in Java Forum Timeline: User interface problems





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC