Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-06-2008, 10:22 PM
Member
 
Join Date: Sep 2008
Posts: 29
Rep Power: 0
whosadork is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 09-06-2008, 10:43 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
Quote:
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-06-2008, 10:51 PM
Member
 
Join Date: Sep 2008
Posts: 29
Rep Power: 0
whosadork is on a distinguished road
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...
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-06-2008, 11:02 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,190
Rep Power: 5
Fubarable is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-06-2008, 11:05 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
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

Quote:
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.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 09-07-2008, 01:32 AM
Senior Member
 
Join Date: Aug 2008
Posts: 302
Rep Power: 1
Supamagier is on a distinguished road
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.
__________________
check out
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
, 100% made by me.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot find imports.. little_polarbear New To Java 4 08-25-2008 03:57 AM
Imports broken in JSP; HTTP Status 500- Aerinai JavaServer Pages (JSP) and JSTL 0 06-13-2008 10:27 PM
How to use Static Imports Java Tip java.lang 0 04-17-2008 07:37 PM
Static imports (Java 5 and above) Java Tip Java Tips 0 12-17-2007 10:02 AM
Organising Imports - Eclipse Java Tip Java Tips 0 11-15-2007 05:15 PM


All times are GMT +2. The time now is 09:30 PM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org