Introduction to Programming with Java Applets (Boese)

Lab: Chapter 1
First Program


The purpose of this assignment is


Instructions:

There are three parts to this lab.

Part 1

Objectives:
  1. Open a term window.
  2. We're going to use an editor available on Linux called gedit. This is the simplest editor and similar to Notepad for Windows. There are more sophisticated editors available (vi and emacs).

    Type:

    	gedit HelloWorld.java
    	
    This opens the gedit editor.
  3. Type in the following code:
    
    /** my first program 
      * @author: 
      */
    import java.awt.*;
    import javax.swing.*;
    public class HelloWorld extends JApplet
    {
        public void paint( Graphics grph )
        {
    	grph.drawString( "Hello World!", 0, 12 );
        }
    }
    
    
  4. Save the file and exit gedit.
  5. Create an HTML file to present the applet.
    Type in the following in a file called Hello.html, using the gedit editor:
      <HTML>
      <BODY>
      <APPLET CODE=HelloWorld.class WIDTH=400 HEIGHT=300></APPLET>
      </BODY>
      </HTML>
      
    
  6. Now compile the program using the javac command.

    Type:

    		javac HelloWorld.java
    	
  7. What happens? If you typed something incorrectly, some errors would print to the screen.
    You will need to fix them before continuing.
  8. Now run it. To run a java program as an applet, use the appletviewer command on your HTML file.

    Type:

    		appletviewer Hello.html
    	
  9. Enter your name after the @author line in the code above. Re-compile and re-run the program and make sure it still works.
  10. Now add an init method, with code to change the background color.
    You can add this code right before the public void paint( Graphics grph ) code
    
    	public void init( )
    	{
    		setBackground( Color.YELLOW );
    	}
    
    
  11. Compile and run the program again. What happens?
  12. Add a line after grph.drawString
    		grph.drawString( "Fine day for a swim!", 15, 100);
    
  13. Compile and run the program again.
    	1.	What is printed in the screen?
    	
    	
    	2.	Change the number 100 to 5, recompile and run it again.  What happens to the output?
    
    	
    	3.	Add your name underneath "Fine day for a swim!".  What is the line you entered?
    
    
    
    

    Part 2 - Using Eclipse

    Now let's run it in Eclipse.

  14. In the terminal window, type in
      eclipse.sh
    Wait for Eclipse, the IDE that we will use to help us program in Java.
  15. The GTA will walk you through setting up the Eclipse environment during recitation.
    Take note of the following:
    	1.	What should you create projects for?
    
    
    	2.	When creating a class, what is the "Source Folder"?
    
    
  16. Name the class HelloWorld.
  17. Show your GTA your run from the terminal window and from Eclipse when you are finished, to get credit for lab completion.

Part 3 - RamCT Submission

Objectives:
  • Learn how to submit assignments in RamCT

    The GTA will lead you in RamCT to access your assignment, submit a file for the assignment, check and verify that it submitted correctly, retrieve the assignment (verify submission status is not submitted), and resubmit a file and verify it.

    It is important to understand how to verify your submissions in RamCT to make sure you actually do hand in your homework on time.
    Remember: This is your responsibility to make sure you submitted your assignments correctly!!

    Instructions can be found at: http://www.cs.colostate.edu/helpdocs/SubmissionsRamCT.html
    and instructions on how to verify your submission are at: http://www.cs.colostate.edu/helpdocs/SubmissionsRamCT.html#VERIFYING


    © by E.S.Boese. All Rights Reserved