Results 1 to 6 of 6

Thread: Imports

  1. #1
    whosadork is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default Imports

    How do i import information from one class to another, wouldn't this be it>>>


    import java.(classname).(classinformation)


    but it dosn't work.

    PS. I have eclypse

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,259
    Rep Power
    25

    Default

    but it dosn't work.
    Please copy and paste the error messages here.

    The import statement is a way to extend the classpath to the location of the class file. The location of the classfile should be at classpath+import-path

    What is the (classinformation) you refer to? Do you have an example?

    import javax.swing.JFrame;
    Where javax.swing is the package and JFrame is the class.

  3. #3
    whosadork is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default

    the class info is an armory, and when i import the class i only want information about the weapons i am making the class about, so it can calculate what the attack is, how much you can sell it for, and when you attack other users how much your attack is.

    so it would be...

    import MyGame.Amory

    then how do i use the information...

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

    Default

    1) missing a semicolon at the end of the import statement.
    2) where's the package information?
    3) AFAIK, you import a class, not "information about a class". If you want to hide implementation details, then use interfaces.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,259
    Rep Power
    25

    Default

    If Amory is a class, create an instance of it using new and then you can call its methods:

    Amory amry = new Amory();
    int value = army.getValue(); // get value

    import MyGame.Amory
    For the above import to find the class Amory, the class file would be in a folder MyGame and the classpath would end at the folder containing MyGame. Amory would be in the package: MyGame.
    If none of this makes sense, go read about packages, classpath and import statement.

  6. #6
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    6

    Default

    in Mygame.Amory, Mygame would be the name of the map Amory.class is in, and Amory should have "package Mygame;" at it's first line.
    I die a little on the inside...
    Every time I get shot.

Similar Threads

  1. cannot find imports..
    By little_polarbear in forum New To Java
    Replies: 4
    Last Post: 08-25-2008, 03:57 AM
  2. Imports broken in JSP; HTTP Status 500-
    By Aerinai in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 06-13-2008, 10:27 PM
  3. How to use Static Imports
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:37 PM
  4. Static imports (Java 5 and above)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-17-2007, 10:02 AM
  5. Organising Imports - Eclipse
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-15-2007, 05:15 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
  •