• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

TextComponent

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bin Wang
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Bin Wang:
Could you please write a simple program to create an instance of TextComponet class?
Thanks.



Since I am part of the java.awt package, I can create a TextComponent object.

 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic