This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Howto Import Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Howto Import Class" Watch "Howto Import Class" New topic
Author

Howto Import Class

Sam Benry
Ranch Hand

Joined: Mar 21, 2008
Posts: 89
Im using Eclipse, and I want to import StdDraw.java
how to do that
I tries
import StdDraw
import StdDraw.java
import StdDraw.class

all are not working, how to import the class?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18532
    
  40

Originally posted by Sam Benry:
Im using Eclipse, and I want to import StdDraw.java
how to do that
I tries
import StdDraw
import StdDraw.java
import StdDraw.class

all are not working, how to import the class?


You need to specify the class, not the file where the class is in.

Open the file, and note the package that the StdDraw class is in. Let's say that it's in some.package, then import via...

import some.package.StdDraw;

Just change some.package to the actual package that StdDraw is in.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18532
    
  40

A couple more points....

First, with Eclipse it is easier than that -- you don't need to open the file. Eclipse will list the package that the java file is in via the package explorer.

Second, if the class that you want to import is in a different project, don't forget to have your project refer to the other project.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Howto Import Class
 
Similar Threads
Drawing Whirl
importing a class..
Convert Swing frame+label to Applet?
JetSpeed Portal Development
I don't understand what I'm being asked.