accessing packages cont'd

Discussion in 'Java' started by Luke, Sep 20, 2003.

  1. Luke

    Luke Guest

    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
     
    Luke, Sep 20, 2003
    #1
    1. Advertising

  2. Luke

    Roedy Green Guest

    Roedy Green, Sep 20, 2003
    #2
    1. Advertising

  3. Luke

    Luke Guest

    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,
    >
    > 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
     
    Luke, Sep 20, 2003
    #3
  4. Luke

    Roedy Green Guest

    On Sat, 20 Sep 2003 16:44:30 +0900, "Luke" <>
    wrote or quoted :

    >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.
     
    Roedy Green, Sep 20, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Woody Splawn

    How Publish VS.net Cont

    Woody Splawn, May 6, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    323
    Woody Splawn
    May 6, 2004
  2. Paul  Smith
    Replies:
    0
    Views:
    734
    Paul Smith
    Nov 18, 2003
  3. gelbeiche
    Replies:
    6
    Views:
    441
    CrayzeeWulf
    Apr 25, 2005
  4. David Lyon
    Replies:
    19
    Views:
    583
    David Lyon
    Apr 24, 2009
  5. Ian
    Replies:
    3
    Views:
    171
Loading...

Share This Page