For this project, you are required to design and create an HTML document (also referred to as a Web page), in which certain basic HTML elements are incorporated. Your HTML document must also link to several Java applets, some of which you will compile yourself from the code provided, and some you will obtain from online sources and simply link to in your HTML document.
In addition, you will input, compile, and test a simple Java application. Unlike Java Applets, which are linked and run from within HTML files, Java applications run freestanding, and can be run from the DOS Command Line.
This project is designed to familiarize you with Java tools and processes, including editing, compiling, and viewing applets and applications, as well as with the methods for using Java Applets in Web documents.
The project does not aim to teach you to program in Java, which is beyond the scope of this course, but rather to familiarize you with the use of the Java environment and tools, in preparation for future courses in programming.
There are two related learning objectives involved:
Your Web page design should use an effective background image or pattern, and various colours, text sizes, and images to create a visually effective design. Your Web page should also include your name, the course name and number, an email link to you, and links to the required Java Applets and navigation links to facilitate easy movement within the pages.
The project has two parts:
The recommended procedure for completing this project is as follows:
Again, it is very important that you carefully review the JAVA PROJECT DEMO to see an example of what the finished project may look like, although you are encouraged to create an original look and feel for your own pages. The applet results seen in Part 1 of the Project Demo must be different from those you will create for your page; i.e., you must compile the code yourself, and not simply copy the compiled class files from the sample.
There are extensive links for tutorials, software tools, and other useful resources at the Virtual Helpdesk. Check both the Course Tools and the Java Helpsections. Links to other required and useful resources can be found below.
ACQUIRING THE TOOLS AND SAMPLE FILES
(NOTE: This is optional. Java code and HTML may also be input and edited using Notepad.)
Functioning Java Class Files for PART 2 may be obtained online from Sun Microsystems Applets page.
You are provided with Java code for two Java applets below. In each case, the text should be typed into either WordPad or a Programmers File Editor, then saved as named, compiled using the javac compiler included in your JDK, and tested using the appletviewer. Finally, the working applets should be linked to Part 1 of your HTML document.
Again, we must stress that you are not expected to learn how to program in Java at this stage, only to develop some familiarity with the tools and processes involved.
Triangle.java
import java.awt.*;
import java.applet.Applet;
public class Triangle extends Applet {
public void paint (Graphics g){
int bottomX=80;
int bottomY=200;
int base=100;
int height=100;
g.drawLine(bottomX,bottomY,bottomX+base,bottomY);
g.drawLine(bottomX+base,bottomY,bottomX+base/2,bottomY-height);
g.drawLine(bottomX+base/2,bottomY-height, bottomX,bottomY);
}
}
Oval.java
import java.awt.*;
import java.applet.*;
public class Oval extends Applet {
public void paint (Graphics g) {
Color c=new Color(20,120,160);
g.setColor(c);
g.fillOval(20,20,60,30);
}
}
Notes on using MS-DOS to run the compiler and appletviewer
The program that compiles your Java code files, creating Applets (class files) which can then be run from an HTML document, is called javac.exe, and is found in the bin folder of your JDK directory. This compiler must be run from an MS-DOS command line, accessible in Windows by selecting Start, Run, and typing CMD.
DOS is a command line interface, which means that you must type in commands to run the program. In this exercise, there are two basic forms these commands will take:
c:windows> cd (Changes the active directory to the root, or main directory)
c:> cd j2sdk1.4.2.xbin (changes the active directory to the jdk bin folder; note that version numbers in the jdk folder name may vary)
c:j2sdk1.4.2.xbin> javac Hello.java (runs the compiler on the desired code file)
Once compiled and linked to an HTML file, the applets can be viewed using either a browser or the Appletviewer.
To link an applet to an HTML page, insert a tag like this into the HTML:
< applet code=“Hello.class“ width=400 height=400 >
< /applet>
You can substitute other Applet (class) names as required.
To view the applet, either load the html page into your browser (e.g., Firefox, Internet Explorer, or other), or run the Appletviewer from the DOS command line. This can be done by switching the active directory to the jdkbin folder, then entering the command:
appletviewer Hello.htm
Again, you will need to substitute filenames as required.
Obtain ONE of the sample applets from here, or any other source for free Java applets you may wish to use. Test the applet, and link it to Part 2 of your HTML page(s).
Functioning Java Class Files for PART 2 may be obtained online from here.