Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / September 2003

Tip: Looking for answers? Try searching our database.

accessing packages cont'd

Thread view: 
Luke - 20 Sep 2003 08:09 GMT
Hi,

My second problem is this:

I have the following hierarachy:
t1/test/test2

then I have source files as follows:
t1/test/test2/Pref.java

t1/test/PrefBean.java

t1/UsePref.java

===========================
the files are like this:
Pref.java:
===========================
package test2;

public class Pref
{
   // attributes
   private String reason;

   // constructor method
   public Pref()
   {
   }

   // methods
   public String getReason()
   {
       return reason;
   }

   public void setReason(String reason)
   {
       this.reason = reason;
   }
}
=============================
PrefBean.java
=============================
package test;

import test2.*;

public class PrefBean
{
  // constructor method
  public PrefBean()
  {
  Pref p = new Pref();
  }
}
=============================
UsePref.java
=============================
package t1;

import test.*;
import test.test2.*;

public class UsePref
{
  // constructor method
  public UsePref()
  {
  PrefBean pb = new PrefBean();
  Pref p2 = new Pref();
  }
}
=============================
As you can see I want to access 'PrefBean' and 'Pref' from 'UsePref'.
However I try, I can't get it working.
I'm using java 1.4.2

Can someone help please!
Can you get this working on your machine

kind regards,
Luke
Roedy Green - 20 Sep 2003 08:28 GMT
>package test2;

you can't do that.  You have to keep all your package names relative
to the same base directory.

see http://mindprod.com/jgloss/package.html
and http://mindprod.com/jgloss/import.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Luke - 20 Sep 2003 08:44 GMT
Hi,

I solved that prob, I believe

I changed each class's package directive to be:
for t1/test/test2/Pref.java:  package t1.test.test2;
for t1/test/PrefBean.java: package t1.test;
for t1/UsePref.java: package t1;

and the import directives to
for t1/test/PrefBean.java:
    import t1.test.test2.*;
for t1/UsePref.java:
    import t1.test.test2.*;
    import t1.test.*;

then I went to the parent directory of t1 and did:

javac -d . t1/*.java

this caused all the classes to compile.
and my computer to smile :-]

the article that helped was:
http://www.cs.wisc.edu/~hasti/cs368/JavaTutorial/NOTES/Packages.html

I'll be posting my 3rd problem shortly.
Thanks for being a listening post,

kind regards,
Luke

> Hi,
>
[quoted text clipped - 79 lines]
> kind regards,
> Luke
Roedy Green - 20 Sep 2003 19:04 GMT
>I changed each class's package directive to be:
>for t1/test/test2/Pref.java:  package t1.test.test2;
>for t1/test/PrefBean.java: package t1.test;
>for t1/UsePref.java: package t1;

Normally you put more than one class in package, but you seem to have
grasped the naming conventions.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.