Using Eclipse in CompSci 4
Addendum for Creating Applets in Eclipse
For the purposes of these notes, we are going to deal with a project
named Iliad and a package named homer and a class
named Troy.
You need to substitute the actual names of
project, package, and class(es) you want to work on.
The details apply to the machines
in 229 Social Sciences, the ICC. Other Windows environments are very
similar.
Using Eclipse
- Starting Eclipse
- Double Click on Classroom Applications on the Desktop
- Double Click on eclipse.exe
- Making a Project
- File->New->Project
- Java->Java Project
- Click on Next
- For Project Name type Iliad
- Click on Finish
- If asked: Switch to Java Perspective? Yes
- Creating a Class
- Select (Click on) Iliad
- File->New->Class
- Name: Troy
- SuperClass: java.applet.Applet
- If there is a check before "public void main(String[] args)"
unclick this box.
- Finish
- Editing Source Code
- Make sure you add an public void init() method
- Add the required code as needed
- (Don't make too many changes before recompiling)
- (It will usually be easier to locate errors after limited
changes>
- Click on the diskette icon to save
(or File->Save)
- Compiling Source Code
- Always be sure to save any changes before compiling
(Unsaved files show an asterisk in the fields above the main window.)
- Select (Click on)Iliad
- Project->Rebuild Project
- Executing Your Program
If any changes were made, you must Compile first (see above).
- Click on Homer.java
- Run->Run as->Java Applet
- Saving Project Locally
- Click on Iliad
- File->Export
- Select Jar file
- Click on Next
- Jar file: click on Browse
- double click on My Computer
- Use filename myhomer.jar
- Click on Save
- Click on Finish
Local Testing
To run/test the applet on the local machine using a web browser
(running it in Eclipse uses a piece of software called the appletviewer)
you can do the following: (It is assumed that you have created myhomer.jar
as shown in the previous step.)
- Create an HTML file that invokes the applet
- Use any tool that you want to create a web page
- it must include:
<applet code="Troy.class" archive="myhomer.jar"
height=200 width=200></applet>
- Save it with the name myhomer.html
- Under Windows you should be able to double-click on
myhomer.html. This should bring up a web page which, in turn,
should start the applet.
Saving Project (Installing in Web Page Directory)
You should now have myhomer.jar and myhomer.html on
you desktop. To allow access from any browser, these must be copied
to the appropriate location on your acpub file system.
- Starting with My Computer browse:
- to the P: drive,
then public_html folder, then your cps4 folder.
- Drag both myhomer.html and myhomer.jar to
the cps4 folder.
(This will copy them.)
- Now, using any browser,
use the URL: "http://www.duke.edu/~yourloginid/cps4/myhomer.html"
This should run your applet
- You can also put a link to myhomer.html, into an existing web page.