Hao Sun
Hao Sun

Reputation: 31

Simple hello world program in java with Eclipse

import acm.graphics.*;
import acm.program.*;
public class HelloProgram extends GraphicsProgram {
   public void run() {
      add(new GLabel("hello, world"), 100, 75);
   }
}

I learned this code on http://people.reed.edu/~jerry/121/materials/artsciencejava.pdf page 23. However , when I run it in Eclipse , it shows many errors. It said I can't import cam.graphics.* and so on. Can anyone tell me what to do ? Thanks so much!!!!

Upvotes: 0

Views: 1007

Answers (3)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285403

You haven't added the appropriate external libraries to Eclipse's build path. Do you have the acm jar files? If so, right click on your project and add the library paths to your build path.

enter image description here

After clicking on Build Path, then click on Add External Archives...

Note, I've made this answer a Community Wiki so that I won't benefit from up-votes and so all can edit and improve this answer.

Upvotes: 4

braden.groom
braden.groom

Reputation: 325

Download the java library that he is using here:

http://jtf.acm.org/acm.jar

Then add the library to your build path as described here:

http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)

Upvotes: 1

Bohemian
Bohemian

Reputation: 425003

  1. Download the acm package of the JTF project - click here for the download.
  2. Save acm.jar into a folder on your computer (perhaps one near your project files)
  3. In Eclipse, right-click on your project: Build Path > Configure Build Path > Libraries > Add External Jars then select the jar file you just downloaded

Upvotes: 0

Related Questions