Results 1 to 3 of 3

Thread: Very simple q

  1. #1
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default Very simple q

    Can someone explain this to me


    //create the button
    JButton button = new JButton("Button");


    ok am i right that JButton is like what tells it what it is like a keyword,

    button is the name of the button


    but, after that i forget what the other 2 names are for and what there purposes are .


    this is a constructor right?

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    JButton is an A class or data type, that is bundled in the Java standard API.
    button is the name of an instance variable, or an identifier in technical terms I guess.
    Equals is the assignment operator of course.
    Yes, new JButton("Button") this is a constructor, in this case takes one argument of type String, that according to the API documentation will be used by the constructor in the object to set the name that this object will display.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,767
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by fresh83 View Post
    Can someone explain this to me


    //create the button
    JButton button = new JButton("Button");


    this is a constructor right?
    To be exact: that is the 'new' operator; that operator always calls a constructor from a class. The 'new' operator allocates the raw memory for the object, initializes it to all bits zero and calls the constructors. Finally it returns the newly created object.

    kind regards,

    Jos

Similar Threads

  1. Simple AI?
    By Atriamax in forum New To Java
    Replies: 4
    Last Post: 12-23-2009, 11:35 PM
  2. New simple application using a simple database
    By webbusiness23 in forum New To Java
    Replies: 9
    Last Post: 08-03-2009, 03:55 AM
  3. Simple Help....
    By jpnym15 in forum New To Java
    Replies: 1
    Last Post: 11-11-2008, 03:33 PM
  4. Replies: 2
    Last Post: 05-04-2008, 06:27 PM
  5. simple GUI
    By dim_ath in forum New To Java
    Replies: 3
    Last Post: 01-07-2008, 04:00 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
  •