Things That Are Useful to Keep in Mind.
Part I
This is my little fact/help sheet for those of you who are somewhat confused with what your applets are doing. If you're a little confused, read through this. Don't take anything as the pure and holy truth because I am subject to error as much as (if not more than) anyone else; but this will give you a better understanding of what's going on and what to keep in mind. So, read through this, and it'll help you out. |
Office Hours
Compiling
Viewing
Methods
Errors
Stages
Indenting
Office Hours are nice.
For those of you having trouble understanding what the computer is doing, while there's no guarantee that we can explain it to you, you will usually find information in Office Hours. To find when office hours are, go to the course web page and check the course calander. They may be moved to a separate page in the future but right now they are on the top right of the course calendar. They are usually going to be held near the elevators on Wean on the fourth floor by the restrooms. If not there, try the seventh or eighth floor. There should be a sign or something letting you know if we've moved. For some of you, two classes a week is not enough to understand what's going on. So......Office Hours.
Compiling with "javac"
Know it. Remember it. Use it.
"javac.exe" is the program we use to compile our
Viewing with "appletviewer"
Know it. Remember it. Use it.
"appletviewer.exe"
is one of the programs thatwe use to view our applets. I highly recommend it as opposed to Netscape or Internet Explorer
because it will give you more detailed errors if there is something wrong with your applet. Sometimes they will
compile but not run. This is because the syntax or how things are phrased may be right but there may be something more
conceptually wrong with the program. You use it by typing in the Dos Command Prompt "appletviewer
Lab3.html" where the Lab3.html file uses the Some things are
case sensitive What is case sensitive? Case sensitive is simply that Ais not the same as a. We see the alphabet
( What things are case sensitive? Well, the
declaration in your applet, which looks like"public class Lab3 extends Applet"
should match thefilename of the .java file. So, the .javafile
should be saved as Lab3.java. The program Some other things that are case sensitive are Andrew
and Java. When you upload your Methods What is a method? My definition: A method is something you can call (tell the program to do or run) that
can do something. Simple, huh? A method can take in information. It can modify it or use it to do something, and it can
return information. When defining amethod, we write the method's header which describes what the method uses and returns.
Such as "void fillRect(int x, int y, int w, int h)" this method takes in four
integers to make a rectangle and returns no values. The first two integers are to define the top left corner of the
rectangle by going right
Example: g.fillRect(23, 43, 290, 355);
Or myGraphicsObject.fillRect(value, 34, width, height);
where value, width and height are variables with integers stored in them and the nameof the graphics object is declared. See Lab 2 that you copied from page 25.
paint is a method.
public void paint(Graphics nameOfObject)
{
}
Its declared public (things outside the class can call it) and it returns void (nothing) and in this case it takes in a variable or object of type Graphics. We usually call the object g, but in this case the name of the object as it exists inside the braces will be nameOfObject. Whats within the braces {} is the methods body. This is what the paint function does.
Errors are good
No, Im not insane; errors are good. You learn from making mistakes and going back and fixing them. Also, you get a nice rewarding feeling when you get them to go away. Before asking for help, take a look at the error message, go to that line and look for something out of place. Check other sample codes in the book and try to determine what is wrong. You will learn much more and much better from this than we if simply tell you what's wrong.
Write programs in stages
You can either write the program all at once. Then try and compile it and possibly get fifty errors, all interrelated and try to deal with it then. Or do it in steps and deal with the problems as they come. (The second one is nicer) Start by taking something that works or a hollow applet. Like the one on page 32 of the book. Make sure that it compiles. Then add a couple things here and there. Compile. Take a look at it. Continue with this process until you have a finished product.
Indenting and being neat
Indentation is a mildly important thing to do. It helps you read your code better andthis is extremely use full when trying to track down and error. Think of it as a termpaper. Say you wrote this twenty page paper on Anthropomorphic behaviors of Holothurians in the South Pacific without ever hitting the enter key, tab key or the space key. Then remembered you misspelled Mollusk as Mollusc and had to go back by handand find Mullusc? Yeah. Or what about asking someone else to find where you misspelled Mollusk? So indent. Its nice sometimes.
How to indent.
I indent by moving in a set amount each time I type a
To Be Continued
(Maybe)