TextComponent tc=new TextComponent(); //compile error: no constructor matching TextComponent()found in //java.awt.Textcomponet I checked Java API and found out that there is no constructor listed for TextComponent. Just as there is no construtor listed for java.lang.Math class. Does that mean TextComponent also has private constructor, so it can't be instantiated? If the API doesn't list constructor for a class, that class has private construtor? Thanks.
I couldn't find any thing either on creating a TextComponent object, but was wondering if this Rules Roundup #27 question fits the above case..? Class Y is a subclass of class X. Will this compile? X myX = new Y(); //answer given is Yes ...so does that mean Component c = new TextComponent(); would work? I would think not, but thought of RR#27 when I read this post. SteveII
Originally posted by Thomas Paul: When in doubt, check the source code. There is one constructor in TextComponent that is "package" access. So only classes in the same package can create a new TextComponent.
Hi Thomas, where can I check the source code? Could you please write a simple program to create an instance of TextComponet class? Thanks.
Hi Bin, To extract source code for the Java Class files, check your JDK directory for a src.jar file. In the same directory, enter jar tf src.jar > srcList.txt This will create a text file listing all the .java files in the src.jar file. View the text file to locate the path name of the class you're interested in and then type: jar xf src.jar file pathname For example, to extract the Reader.java file jar xf src.jar src/java/io/Reader.java Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform