Most of the programs that we will write for this class will be stand-alone programs. However, Java also enables a way to write Applets which are programs that run through a browser. For this lab warm-up you can learn how to create java applets and incorporate them into a webpage. The applet you will compile and use is the blinking text applet above. This will also get you familiar with whatever java programming environment you choose to use so you can just start on the first programming assignment next week with all these details worked out.
For this lab you should turn in the java applet you designed and a link to a webpage with this applet running. To turn in it, log in to the UCI Electronic Educational Environment, and upload (1) your applet and (2) a link to your webpage.
Java Applets are programs that can be run through a web browser. This section will guide you through two different ways of running an Applet: through a web browser or through BlueJ. In order to run any program or Applet through BlueJ, you have to first create a project and put the appropriate files in the project. This is something that is required by BlueJ, and is its way of organizing files for a particular application.
Start out by opening up BlueJ through the Start menu. ( All the machines in the lab already have BlueJ installed. If you would like to install BlueJ on your own computer visit http://www.bluej.org . ) Since we are creating a new project, pull down the Projects menu in BlueJ and choose New Project. Select the location where you want your project to reside and give your project a name. This will create a folder with that name and two additional files in the folder.
To run a Java Applet through a web browser, you will need at least two different files: an html file and at least one file containing the Java bytecode for the applet. The name of the html file will always have the extension .html and the names of the files containing the Java bytecode will always have the extension .class . The .class file is created by compiling Java source code which will be stored in files ending in .java . Copy the Blink.java file into your project folder.
If we want to run the Applet through BlueJ, we need to add the new Java source file to the project. From the Edit menu in BlueJ, select Add Class From File. Select Blink.java and click Add . A box with the name of the applet (Blink) will appear in your window. Click on the Compile button to compile the project. This will produce a file called Blink.class in the project folder which is the Java bytecode for the applet.
To run the applet, right click on the box with Blink applet and select Run Applet . You can run the applet through the applet viewer or the web browser. Experiment with both. For now, select one and click OK . When you run the Applet, BlueJ automatically produces an html file that points to the bytecode file for that applet.If you right click on the Blink applet and select Open Editor you can edit the java source code. You will need to do this when you develop your own Java programs. Go in and edit the text that is blinking in the applet.
Go back to the folder containing the files for your project. If you double-click on the Blink.html file, your browser will open and display your new applet. If you open the html file with a text editor, you can see and edit the html file. Note the line that points to the Blink.class file. This tells the browser to execute this bytecode.