Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: actionPerformed Question.

  1. #1
    Member
    Join Date
    Sep 2011
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default actionPerformed Question.

    I want to get a better understand of the following code:

    exitItem.addActionListener(new ActionListener(){
     
    			public void actionPerformed(ActionEvent e){
     
    				System.exit(0);
     
    			}
     
    		});

    I know that the method addActionListener has to have the parameters of an ActionListener which defines what to do when the action occurs.

    The part which I dont understand is the parameter of the actionPerformed method, I can see that it accepts an ActionEvent object and is calling it "e", my question is what does it do with the object?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: actionPerformed Question.

    It does whatever you want it to do. From that parameter, you can get things like the time the event occurred, which keys were pressed at the time, etc. Different Events will have different properties- a MouseEvent has x, y, which button was clicked, etc.

    Your first stop for questions like these should always be the API: ActionEvent (Java Platform SE 6)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. actionPerformed not returning a value.
    By gher in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 22nd, 2011, 10:15 AM
  2. Tic Tac Toe ActionPerformed Issue
    By Jakesta42 in forum What's Wrong With My Code?
    Replies: 19
    Last Post: August 14th, 2011, 11:11 PM
  3. Needed help in actionPerformed statements
    By S-NESH in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 7th, 2011, 06:36 PM
  4. actionPerformed method
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 4th, 2010, 02:29 AM
  5. actionPerformed
    By Kumarrrr in forum Java Theory & Questions
    Replies: 5
    Last Post: November 23rd, 2010, 09:08 AM