Results 1 to 2 of 2
  1. #1
    atch is offline Member
    Join Date
    Feb 2010
    Posts
    8
    Rep Power
    0

    Lightbulb Very strange structure

    Hi could anyone explain to me what is going on with the structure of the code below? I mean, what I understand from it that enrolButton want to register some ActionListener which is created inside of this call and method actionPerformed is overwritten, but:
    1. I just cant understand the syntax
    2. I always thought that you can't define method into another method especially in a method call.

    Java Code:
     enrolButton.addActionListener(new java.awt.event.ActionListener()
            {
                public void actionPerformed(java.awt.event.ActionEvent evt)
                {
                    EnrolButtonActionPerformed(evt);
                }
            });
    Thanks for any help

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    It's a shortcut. Take out the code that looks like
    Java Code:
    new java.awt.event.ActionListener()
            {
                public void actionPerformed(java.awt.event.ActionEvent evt)
                {
                    EnrolButtonActionPerformed(evt);
                }
            }
    That's a new object being created from a class which is a subclass of ActionListener. We don't need to give this subclass a name since we are only worried about the behavior of the method actionPerformed.

Similar Threads

  1. Strange behaviour in serialization
    By Wolverine in forum Networking
    Replies: 0
    Last Post: 05-23-2009, 01:03 PM
  2. strange swt exception
    By ahmed.kotb in forum SWT / JFace
    Replies: 0
    Last Post: 04-23-2009, 11:15 AM
  3. strange code
    By tghn2b in forum New To Java
    Replies: 3
    Last Post: 12-23-2008, 12:51 AM
  4. Strange problem
    By Tamir in forum Eclipse
    Replies: 1
    Last Post: 08-18-2008, 10:44 PM
  5. Strange behaviour in swing
    By cbalu in forum AWT / Swing
    Replies: 1
    Last Post: 05-23-2008, 10:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •