Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: packages

  1. #1
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default packages

    Hi again.

    Ok so I have been developing a zelda clone. It works beautifully. I just want to clean up and organize my project folder. I started with everything in the same folder. To begin organizing, I put everything I haves as text data files in folders. Now I have maps, images, scripts, saves, and dialogs folders, and edited my game code to load/save everything to the appropriate folders.

    Where I'm stumped is I have a lot of tools, ex. ImageTools.java, IOOperations.java, and TileSet.java to name a few. I also have a million game objects, for ex. gameProp.java, GameEnemy.java, and GameNPC.java to name a few. What I would like to do is put all the tools in a Tools folder and all the objects in an Objects folder.

    I tried so far by adding "package ImageTools;" for example to the top of each tool, using the tool's name
    I then placed every tool into the Tools folder and javac'ed everything, and this was the result.
    I also added import Tools.*;
    I then tried import Tools.toolName.*;

    Further down I was trying to put everything into separate folders within the Tools folder.
    this has been edited for an easier read.

    C:\JSource\MyGame>javac MapMaker.java
    MapMaker.java:36: cannot access Tools.IOOperations
    bad class file: .\Tools\IOOperations.class
    class file contains wrong class: IOOperations
    Please remove or make sure it appears in the correct subdirectory of the classpath.
      private IOOperations ioObject;
              ^
     
     
    C:\JSource\MyGame>javac MapMaker.java
    MapMaker.java:36: cannot access Tools.IOOperations
    bad class file: .\Tools\IOOperations.class
    class file contains wrong class: IOOperations
    Please remove or make sure it appears in the correct subdirectory of the classpath.
      private IOOperations ioObject;
              ^
     
    C:\JSource\MyGame>javac MapMaker.java
    MapMaker.java:15: package Tools.WindowCloser does not exist
    import Tools.WindowCloser.*;
    ^
    MapMaker.java:40: cannot access Tools.IOOperations.IOOperations
    bad class file: .\Tools\IOOperations\IOOperations.java
    file does not contain class Tools.IOOperations.IOOperations
    Please remove or make sure it appears in the correct subdirectory of the classpath.
      private IOOperations ioObject;
              ^
     
    C:\JSource\MyGame>javac MapMaker.java
    MapMaker.java:15: package Tools.WindowCloser does not exist
    import Tools.WindowCloser.*;
    ^
    MapMaker.java:40: cannot find symbol
    symbol  : class IOOperations
    location: package Tools
      private Tools.IOOperations ioObject;
                   ^
    MapMaker.java:41: cannot access Tools.ImageTools.ImageTools
    bad class file: .\Tools\ImageTools\ImageTools.class
    class file contains wrong class: ImageTools.ImageTools
    Please remove or make sure it appears in the correct subdirectory of the classpath.
      private ImageTools iT = new ImageTools();
              ^
     
    C:\JSource\MyGame>javac MapMaker.java
    MapMaker.java:11: package Tools.DecoratedIcon does not exist
    import Tools.DecoratedIcon.*;
    ^
    MapMaker.java:12: package Tools.ImageSplitter does not exist
    import Tools.ImageSplitter.*;
    ^
    MapMaker.java:13: package Tools.ImageTools does not exist
    import Tools.ImageTools.*;
    ^
    MapMaker.java:14: package Tools.IOOperations does not exist
    import Tools.IOOperations.*;
    ^
    MapMaker.java:15: package Tools.WindowCloser does not exist
    import Tools.WindowCloser.*;
    ^
    MapMaker.java:40: package Tools does not exist
      private Tools.IOOperations ioObject;
                   ^
    MapMaker.java:41: cannot access ImageTools
    bad class file: .\ImageTools.class
    class file contains wrong class: ImageTools.ImageTools
    Please remove or make sure it appears in the correct subdirectory of the classpath.
      private ImageTools iT = new ImageTools();
              ^
     
    C:\JSource\MyGame>javac MapMaker.java
    MapMaker.java:35: cannot access IOOperations
    bad class file: .\IOOperations.java
    file does not contain class IOOperations
    Please remove or make sure it appears in the correct subdirectory of the classpath.
      private IOOperations ioObject;
              ^

    Is there a way to do this?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: packages

    put all the tools in a Tools folder and all the objects in an Objects folder.

    I tried so far by adding "package ImageTools;"
    The package name and folder name must be identical.

    For what its worth, if you these 'tools' are general enough, you might consider creating a separate project (perhaps the same package name) and jar this up - then add this jar to the classpath of your main project. This allows you more freedom to reuse these classes in different projects simply by adding the library to the classpath.

  3. #3
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: packages

    I was thinking maybe combining the tools and objects classes into one tools.class and objects.class with delicately crafted constructors.

Similar Threads

  1. Packages and Servlets
    By god1gracious in forum Java Servlet
    Replies: 3
    Last Post: October 1st, 2011, 10:05 AM
  2. Meaning of Java Packages
    By Effrego in forum Java Theory & Questions
    Replies: 1
    Last Post: February 5th, 2011, 05:18 PM
  3. Problem with Packages
    By pirezas in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 12th, 2010, 03:41 PM
  4. [SOLVED] Confuced when import packages...
    By Delmi in forum AWT / Java Swing
    Replies: 2
    Last Post: May 20th, 2010, 03:39 AM
  5. importing packages..
    By chronoz13 in forum Java IDEs
    Replies: 4
    Last Post: November 23rd, 2009, 05:49 PM