Comp101 Lab 2


In this lab you will do your first actual java programming, creating objects and calling methods. You will contine to get used to the Unix computing environment. A considerable part of this lab is spent in getting used to the tools you will use to write and build your program.


Assignment Specifications

In this lab you will take preexisting files and finish them to create a Ganan flag. (Why Ganan, because it is one of the Bar flags that I've not done yet). When you are finished, your program should look like this when you run it:


Copying the files

First you'll need to copy the starter files over to your directory.
cp /home/bscstaff/jsantore/ .
and then unzip the files
This has created a folder called Lab2 in your home folder. Make the Lab2 folder your working folder (using the cd command appropriately as you learned in the last lab) Then see what files are there using the ls command.

Start using xemacs

This section is best done either on campus, or from a genuine highspeed connection (not the cable modem that is heavily used by everyone else on the street)

One of the files that you just unzipped is named This is the file that you will need to work on. So open this file using xemacs. From the command line type:

emacs &

This may take a few seconds to come up fully. There is some configuration for using java that gets done when starting emacs. From off campus emacs may take as long as a minute to startup. You should see something like the following:
xemacs with open

You see that the file is nicely "pretty printed" with comments in blue, java keywords in a a sort of pale purple and so on. xemacs will also help you to indent your code later on when you are writing more extensive programs.

The program runs as it is, it just doesn't do very much. Before we can run any program,  we must compile it. 

To compile, go back to your command line and type:


Running the program.

Now lets run your program. We run a program in java by using the command java and then the name of the class with the main method in it. In our case

java Comp101Lab1 &

You may get a warning about a font, this is only a warning and the font will just look a little ugly. After running the program you will see a nice gray window like the one below:
initial look of the window

Congradulations, you are now ready to begin writing your part of the program.

Writing Java code.

In order to make your Ganan flag appear, you must create three objects and call a method on each one. All of your object creation code should be placed in the setup() method of the Comp101Lab1 class. You will find two lines of comments that read:
//comp101 lab2 the code for object creation goes here

 //comp101 lab 2 all object creation code must be above here.

Put all of your object creation code between these two lines of comments.

Put the code to call methods in the paint method in the Comp101Lab1 class.
//comp 101 lab2 put your code for method calls here

 //all your code should be above here

put all of your method calling code between these two lines of comments.

You need to

When you have created the three objects and called show on each one, compile your program again, fix any errors in compiling and then run it again. If you see the complete flag from the first image above, you are done the program. Note that I've run into a Java bug occasionaly which forces you to minimize and then restore the window to see the flag sometimes.


To submit your program, zip up the entire Lab2 folder (as you zipped the lab1 folder last time) and submit using the online submission program that we used for lab 1

cd ..
zip -r <your last name> Lab2

Refer to the last lab for a refresher on how to do this.

Due Date. 

This lab is due at 11:59pm on the day before class one week from now.