Results 1 to 6 of 6
  1. #1
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Some questions about packages.

    I am working on a text editor and it's starting to become a decent amount of files and I would like to organize them better.

    So far I have a source file which is the actual text editor, which handles all saving and font changing. The file uses actions which I would like to store in a folder.

    For example I have
    Java Code:
    public class SaveAction extends AbstractAction{}
    public class OpenAction extends AbstractAction()
    there are 12 action classes in total. I would like to store them in a path of
    Java Code:
    c:/javacode/texteditor/actions
    I packaged them all like this
    Java Code:
    package texteditor.actions;
    I would have the actual text editor in the the path of
    Java Code:
    c:/javacode/texteditor
    and packaged with
    Java Code:
    package texteditor;
    My classpath points to the javacode directory.

    Here is where I am running into trouble. All the actions have an instance of a text editor and the text editor has an instance of the actions. When I try to compile any of the code I get errors for all the instances of the other class. When compiling the actions I get errors for the text editor references, when compiling the texteditor I get errors for every reference to any action.

    It seems like it's a circular problem where each file relies on the other being already compiled.

    Any way to do this? I hope I am making myself clear.

    Finally, if I can compile the code, does it matter where the class files need to be stored? Or can they be anywhere that the classpath can get access to?

    Thanks for any help guys.

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by sunde887 View Post
    Finally, if I can compile the code, does it matter where the class files need to be stored?

    no, as long as all packages/classes are in the same project-root you can use any class in any package, but you must either import the classes you want to use or you must use the full package path when you use the class.

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Thanks for that. As for my other question, here is an example of what I am having trouble with.

    This is in the directory
    Java Code:
    c:/javacode/test
    Java Code:
    package test;
    
    import test.package1.*;
    
    public class A{
    	private B x = new B(this);
    }
    and then b is in the directory
    Java Code:
    c:/javacode/test/package1
    Java Code:
    package test.package1;
    
    import test.*;
    
    public class B{
    	private A x;
    	public B(A x){
    		this.x = x;
    	}
    }
    errors when attempting to compile A
    Java Code:
    a.java:3: package test.package1 does not exist
    import test.package1.*;
    ^
    a.java:6: cannot find symbol
    symbol  : class B
    location: class test.A
            private B x = new B(this);
                    ^
    a.java:6: cannot find symbol
    symbol  : class B
    location: class test.A
            private B x = new B(this);
                              ^
    3 errors
    When I compile b
    Java Code:
    C:\Javacode\Test\Package1>javac b.java
    b.java:6: cannot find symbol
    symbol  : class A
    location: class test.package1.B
            private A x;
                    ^
    b.java:7: cannot find symbol
    symbol  : class A
    location: class test.package1.B
            public B(A x){
                     ^
    2 errors

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Wow, I love you Fubar, when I read online it said to make package names lowercase so I assumed, and clearly made an ass of myself. Thanks very much for the help you guys.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. packages
    By fogus in forum New To Java
    Replies: 1
    Last Post: 03-24-2009, 07:14 AM
  2. Replies: 3
    Last Post: 02-12-2008, 12:03 PM
  3. Using packages
    By prfalco in forum New To Java
    Replies: 5
    Last Post: 01-31-2008, 11:38 PM
  4. packages
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 01:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •