Why the method can be called in this way?

Hi all,
The following is JAVA SWING TREE custom data models program. There are two files in the program: one is TestFrame.java, and the other is MyDataModel.java. I only posted the important part on the Forum.My question is how method getChild(...) in MyDataModel.java was called in the program? Why I couldn't see the statement like tree.getChild(..) in TestFrame.java? After adding PRINT statements, I know the method getChild(..) was called automatically when object tree was initialized , but I don't know why. Thank you in advance.
======
TestFrame.java
// Imports
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
class TestFrame extends JFrame
// Instance attributes used in this example
private JPanel topPanel;
private JTree tree;
private JScrollPane scrollPane;
// Constructor of main frame
public TestFrame()
// Create a new tree control
MyDataModel treeModel = new MyDataModel( root );
tree = new JTree(treeModel);
=========
==========
MyDataModel.java
import javax.swing.tree.*;
class MyDataModel extends DefaultTreeModel
private DefaultMutableTreeNode root;
private String rootName = "";
public MyDataModel( TreeNode root )
super( root );
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)root;
rootName = (String)parentNode.getUserObject();
System.out.println("rootName is: "+rootName);
public Object getChild( Object parent, int index )
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)parent;
String parentName = (String)parentNode.getUserObject();
System.out.println("parentName is: "+parentName);
if( parentName.equals( rootName ) )
return super.getChild( parent, index );
else
return new DefaultMutableTreeNode( cardArray[index] );
}

This is the first time I saw this usage. I understood it now, but I was afraid I missed some important concepts on "interface as parameter in the constructor". Therefore, I am wondering where I can find some online document about it in order to understand the usage clearly.
For example, if there are a few method implementations of interface TreeModel in MyDataModel.java, which methods will it call after calling JTree constructor? all methods or only part of them?
Thanks

Similar Messages

  • The window shrinks down and when you expand it the writing isn't there it only shows the small part that does open. Most of the games can't be played this way!

    When you click to play the game, the window shrinks down and when you expand it the writing isn't there it only shows the small part that does open. Most of the games can't be played this way, you can't read the chat or access most of the buttons!!! It is just the newest version of Firefox because it works fine on my other computer that hasn't been updated and it also works fine in IE.

    See:
    *http://kb.mozillazine.org/Prevent_websites_from_disabling_new_window_features
    *http://kb.mozillazine.org/JavaScript#Advanced_JavaScript_settings
    * http://kb.mozillazine.org/browser.link.open_newwindow
    * http://kb.mozillazine.org/browser.link.open_newwindow.restriction

  • Why doGet() method wil be called default in servlet

    hi
    my first question is
    1.why doGet() method wil be called up first instead of doPost() method in servlet. .
    2. How to identify the browser disables the cookies.
    please help me to this questions.
    Thank u in advance.

    hi
    my first question is
    why doGet() method wil be called up first instead of
    doPost() method in servlet.This is not correct. doGet or doPost getting called depending on the request method of the HTTP request. If the request method is GET then doGet will get called, if the request method is POST then doPost will get called.
    By the way there are other request methods. If a request arrives with one of those request methods the corresponding doXXX method wil get called.
    2. How to identify the browser disables the
    cookies. There is no direct method. What you can do is set a cookie and then see if it is sent back with the next request from the same browser session.

  • Why the AWT components are called heavy-weight and SWING as light-weight?

    Why the AWT components are called heavy-weight and SWING as light-weight?.
    Building our own components means overhead on JVM. hence in what sence the SWING components are called light weight.?
    I know that the Swing componets are the components which are not going to depend upon peer classes and render, OS independent LOOK n FEEL.
    Thanks,
    Sanath Kumar

    All extensions of Component are considered lightweight since, as you point out, they don't have their own dedicated native peer.
    Essentially a lightweight component only has a canvas on which to draw itself and some means of receiving events from the system. In fact, there is no need to have one of these "canvas" and "event" objects for each component - the parent component can manage these abilities on behalf of its children. Eventually you end up with only top-level components needing to be heavyweight in order to communicate with the windowing system.
    A lightweight component therefore has the minimal dependency on the underlying windowing system giving you maximum cross-platform flexibility.
    It is usually true that lightweight => slower and heavyweight => faster since it is reasonable to assume that native peers will be optimal for the windowing system. However, that's not the point of the lightweight/heavyweight distinction.
    Hope this helps.

  • Why my Apple ID stopped when I buy and why the supporter can't help and why they don't reply to any email I send

    Why my Apple ID stopped when I buy and why the supporter can't help and why they don't reply to any email I send so what should I do in this moment I need guide and help so as a request please reply me back  Thanks ....

    As I said in my above reply we are fellow users, we won't know why your account is disabled.
    You might be able to re-enable it via this page : http://appleid.apple.com, then 'reset your password'
    You might then need to log out of your account on your phone by tapping on your id in Settings > iTunes & App Store and then log back in so as to 'refresh' the account on it.
    If that doesn't fix it then you might need to contact iTunes Support : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page

  • Why the iphone4 during a call does not keep the 3G?

    why the iphone4 during a call does not keep the 3G?
    I meet a lot of 3G signal when a call signal disappears 3G! I read the manuals and anything I find the problem! I do so with other brands and other cell does not, the same goes when I receive a call!

    Oniplay wrote:
    I tried to restart, the problem still remains.
    Make sure you do a reset, not a restart. Press and hold both buttons, ignore the "slide to turn off" message and let go of the buttons after the Apple logo shows up on the screen.
    If you did that and it did not bring any change, try to set it up as new device, as explained in this article:
    How to back up your data and set up as a new device
    If it does not work the first time, try not to use the backup afterwards in a second attempt, in case it contains corrupt data.
    If still no luck, get it serviced:
    Apple - Support - Service Answer Center

  • When trying to restore and update my ipod touch it comes up with an error message saying: "The ipod can not be restored this device isnt eligible for the requested build"

    When trying to restore and update my ipod touch it comes up with an error message saying: "The ipod can not be restored this device isnt eligible for the requested build" How do i fix this?

    I am having the same issue. I just had the battery replaced at a third party store. The battery powers the ipod up but it needs to be restored. It is saying it isn't eligible for rebuild. I am running MAC OS 10.4.11  itunes v. 9.0   and I just want it to be restored. I need help.  Oh and its an 8 gb ipod touch.

  • When i do initial set up w creative cloud set uo wont run send error message"installer failed to initialize" why and how can i get pass this

    When I do initial set up with creative cloud set up it wont run a send error message "installer failed to initialize" comes up. Why and how can I get passed this?

    Error "Installer Failed to Initialize" | Install desktop application | Windows

  • TS3992 How can I back up an iphone when I haven't set the phone up for back ups & the touch screen doesn't work? The phone can receive calls (not answer) & the pictures & messages can be seen but touch screen doesn't work to unlock the phone or select any

    How can I back up an iphone when I haven't set the phone up for back ups & the touch screen doesn't work? The phone can receive calls (not answer) & the pictures & messages can be seen but the touch screen doesn't work to unlock the phone or select anything. We want to save/transfer pictures, contacts, and music to the replacement phone.

    Try backing it up to your computer with iTunes.  Connect it to your computer, open iTunes, click on the name of the phone in iTunes, go to the Summary tab of your iTunes sync settings and click Back Up Now.  Also go to File>Devices>Transfer Purchases to transfer you apps and other purchased media to your iTunes library.

  • [Q?string]Why the null can be calculated?

    Why the null can be calculated?
    although i know string instances cannot be changed, but i still not very clear about what the null is
    and why the 2nd println results "nullb", is it a new character string?
    why it is not "b" only, or an exception?
    class TestNull
         public static void main(String args[])
              String str_a=null;
              String str_b="b";
              StringBuffer str_Buff=null;
              System.out.println(str_a+str_Buff);//results nullnull
              System.out.println(str_a+str_b);//results nullb
              System.out.println(str_Buff.append(str_a));//results Exception
    }thanks

    although i know string instances cannot be changed,
    but i still not very clear about what the null isNull is a reference literal. It can be assigned to reference variables. A reference variable either contains a reference to an object or it contains null.
    and why the 2nd println results "nullb", is it a new
    character string?It's beacuse println() prints the String "null" when it encounters the null literal. If you add "b" you get "nullb".
    why it is not "b" only, or an exception?That's how println works.

  • Why the !@#$ can't I zoom in/out when cropping a photo??

    Why the !@#$ can't I zoom in/out when cropping a photo??

    Yes, that zoom scroll doesn't change the dimensions of the photo.
    Attached is a screen shot to help explain the issue.
    Notice the top of the guitar is not within the desired dimensions. I would like to zoom out to be able to fit all of the guitar in the cropped section.

  • When I try open a .pdf file my Adobe Reader 11 only allows the download / save opening the related window and don't show me both options 1) open with ... and 2) save as.... probably someone flagged the choise... always perform this way ....

    When I try open a .pdf file my Adobe Reader 11 only allows the download / save opening the related window and don't show me both options 1) open with ... and 2) save as.... probably someone flagged the choise... always perform this way ....
    Could some one give help and let me know where I can probably find the settings option that allows me to change and switch to previous situation where it was possible to decide time to time how to proceed either opening the file or saving it ??
    Thanks in advance
    David

    What is your operating system?
    Open a PDF from where?  If online, in what browser?

  • When I try to work with some photos Imovie gets stuck and then it stops to work at all. It happens only with some specific photos,is there a way to repair them?I can't go on this way,help me please

    When I try to work with some photos Imovie gets stuck and then it stops to work at all. It happens only with some specific photos,is there a way to repair them?I can't go on this way,help me please

    Hi,
    The movie is probably MPEG format.
    QuickTime Pro and iMovie cannot transcode audio contained in MPEG movies.
    Try to convert with SimpleMovieX or MPEG Streamclip instead.
    http://www.aeroquartet.com/SimpleMovieX/
    http://www.squared5.com
    Regards, BJ

  • Why listener methods are getting called twice ?

    Hi Group,
    I have a doubt, i need to know logic behind it.
    Lets consider, JComboBox,
    For an item state change of JComboBox,
    itemStateChanged method gets called twice.
    Its similar with valueChanged getting called twice
    on List Selection Event.
    Why does it call twice ? Is there any way, I can
    have invocation only once (except flagging mechanism)?
    with regards,
    vikram.

    http://java.sun.com/j2se/1.3/docs/api/java/awt/event/ItemListener.html
    tells the following:
    public void itemStateChanged(ItemEvent e)
    Invoked when an item has been selected or deselected. The code written for this method performs the operations that need to occur when an item is selected (or deselected).
    So the listener is notified for both items: losing and gaining selection.
    If you are only interested in listening to either selection or deselection event you can check which was the cause for the method call by examing the ItemEvent parameter i.e. item_event.getStateChange() == ItemEvent.DESELECTED or ItemEvent.SELECTED and then decide whether you are interested in the event at all.
    I don't know how to stop JComboBox from launching both select and deselected events.

  • Why a method can not be invoked in JSP ???

    I define a method in a JAVA Class file,as this:
    public Enumeration getElementsNamed(String name, String parentname) {
    Element elem = doc.getDocumentElement();
    NodeList nodes = elem.getElementsByTagName(name);
    int size = nodes.getLength();
    Vector elemVec = new Vector(size);
    for (int i = 0; i < size; i++) {
    Node node = nodes.item(i);
         if (nodes     .item(i).getParentNode().getLocalName().equals(parentname)) {
              elemVec.addElement(new UddiObject((Element) node));
              return elemVec.elements();
    I want to get a Element who's Localname is the name and his parent Element's laocalname is the parentname from a DOM tree.
    This can be run well in a normal Java environment just as JDK1.4.
    and is a JSP file,I import the Class first.
    and invkoed the method in somewhere, the TOMCAT give me an error:
    The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException     
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
    the JSP file is :
    <%@ page import="java.util.*,org.w3c.dom.*, edu.hunnu.uddi.*, java.sql.*,java.io.*,edu.hunnu.uddiserver.util.*,edu.hunnu.uddiserver.inquiry.*" %>
    <h1>Get tModel</h1>
    <%
         Connection con = SqlConnection.getConnection();
    String Description="";
         String detail ="<get_tModelDetail generic=\"2.0\" xmlns=\"urn:uddi-org:api_v2\"><tModelKey>"+tModelKey+"</tModelKey></get_tModelDetail>";
         ByteArrayInputStream bas = new ByteArrayInputStream(detail.getBytes());
         TModelDetails tmodelDetails = new TModelDetails( new Get_TModelDetail(bas), con);
    UddiObject obj=tmodelDetails.getData();
         obj=obj.getElement(UddiTags.TMODEL);
         Description=Description+((TModel)obj).getDescription();
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              Error at this
              %>
    <%%>
    WHY??? and HOW????

    oh~It is my mistake.
    and the JSP file would be:
    <%@ page import="java.util.*,org.w3c.dom.*, edu.hunnu.uddi.*, java.sql.*,java.io.*,edu.hunnu.uddiserver.util.*,edu.hunnu.uddiserver.inquiry.*" %>
    <h1>Get tModel</h1>
    <%
         Connection con = SqlConnection.getConnection();
    String Description="";
         String detail ="<get_tModelDetail generic=\"2.0\" xmlns=\"urn:uddi-org:api_v2\"><tModelKey>"+tModelKey+"</tModelKey></get_tModelDetail>";
         ByteArrayInputStream bas = new ByteArrayInputStream(detail.getBytes());
         TModelDetails tmodelDetails = new TModelDetails( new Get_TModelDetail(bas), con);
    UddiObject obj=tmodelDetails.getData();
         obj=obj.getElement(UddiTags.TMODEL);
         Enumeration enum=obj.getElementsNamed("description","tModel");
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              Error at this
              %>
    and the variable "obj" :
    <tModel operator="www.hunnu.edu.cn"tModelKey="uuid:50C693A0-7AB8-11D5-93A0-CFE2D4CCB519"><name>simple.services</name><description>This is a basic tModel for service providers and consultant</description><overviewDoc><overviewURL>http://www.hunnu.edu.cn</overviewURL><description>Service documentation can be obtainedfrom the URL provided</description></overviewDoc><identifierBag/><categoryBag/></tModel>

Maybe you are looking for

  • How do I find how a particular dameon is getting started?

    This is a new question prompted by discovering a Canon Scanner process that is getting started on my MacPro. To summarize, I have a Canon Pixma MP800R All-In-One printer. Everything has been working fine but today I've gotten 4 kernel panics in a row

  • FTPS File Receiver CC Error in RWB Pi7.11

    Hi Folks, i am using the file to file scenario using the FTPS Adapter as a receiver while test the scenario i am getting the below Error message : Message processing failed. Cause: com.sap.engine.interfaces.messaging.api.exception.MessagingException:

  • How can I load images without XML, please?

    Hello Everyone, I would highly appreciate it if someone can point me into the right direction. I have some AS2 code which loads up the images via an xml file. I have been asked to eliminate XML entirely and have images be loaded from with in the libr

  • Date field sorting proble !!!

    Hi We are unable to sor the date fields when we copy the report in Excel spread sheet...When sorting this report its pulling only the first 2 numbers We need to download the report and sort by the date fields . we are getting this date fields  from o

  • PO update to info record without FRB1 condition

    Scenario: There is an info record for a vendor/material combination that is purchase org only (not plant specific). A PO is create.  A price for the material is pulled into the PO along with a FRB1 value.  Where is it getting this information.  There