• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Howto Import Class

 
Sam Benry
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21489
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Marshal
Pie
Posts: 21489
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic