Results 1 to 4 of 4
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,036
    Rep Power
    8

    Default {} after new operator, what does it mean?

    simple question:
    usually one would say, concerning the new operator:
    JPanel leftHalf = new JPanel();
    but what happens when {}; are added?
    BTW studying swing stuff....


    Java Code:
    JPanel leftHalf = new JPanel() {
                //Don't allow us to stretch vertically.
                public Dimension getMaximumSize() {
                    Dimension pref = getPreferredSize();
                    return new Dimension(Integer.MAX_VALUE,
                                         pref.height);
                }
            };

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default Re: {} after new operator, what does it mean?


  3. #3
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,036
    Rep Power
    8

    Default Re: {} after new operator, what does it mean?

    Thanks eRaaaa

    Have another simple one:
    I've got a class that extends JPanel
    and declare a button b
    when registering that button like this:
    b.addActionListener(this);

    "this" refers to the JPanel, right?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: {} after new operator, what does it mean?

    Yes.
    Which implies that your subclass of JPanel implements the ActionListener interface.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. Use of this operator
    By anjibman in forum New To Java
    Replies: 2
    Last Post: 09-15-2012, 11:22 PM
  2. Replies: 5
    Last Post: 01-21-2012, 11:02 PM
  3. question about the operator ++
    By dardar in forum New To Java
    Replies: 10
    Last Post: 08-16-2010, 02:39 PM
  4. help with not equal to operator !=
    By manowar689 in forum New To Java
    Replies: 9
    Last Post: 06-15-2010, 12:10 AM
  5. Increment Operator Example
    By abimaran in forum New To Java
    Replies: 10
    Last Post: 11-03-2009, 04:45 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
  •