CSE 113 Week 4 February 4 - 8, 2008

advertisement
CSE 113
Week 4
February 4 - 8, 2008
Monday Announcements
 Software Installation Fest 2/5 & 2/6
4-7 in Baldy 21
 Exam 2 is 2/6
 Module 1 due 2/8
 Module 2 due 2/15
 Exam 3 is 2/15
 Module 3 due 2/22
Wednesday Announcements
 Software Installation Fest 2/6 4-7 in
Baldy 21
 Exam 2 TODAY!
 Module 1 due 2/8
 Module 2 due 2/15
 Exam 3 is 2/15
 Module 3 due 2/22
Friday Announcements




Module 1 due 2/8 (TODAY!)
Module 2 due 2/15
Exam 3 is 2/15
Module 3 due 2/22
Monday
 Another look at this bit of code:
Turtle t1 = new Turtle();
Turtle t2 = new Turtle();
t1 = t2;
 Both t1 & t2 refer to the same turtle
and the turtle that was referred to by
t1 is no longer accessible in the
program.
Monday
 We can actually modify the turtle’s
source code to include methods that
we define.
 We need to open up the Turtle.java
file in the editor pane and find where
the methods should go.
 Then we can write our own method
definitions.
Monday
 Method definitions look like this:
public returnType methodName (parameter list)
 Where the return type is the type of
information we want to get back from
the method (or void if there is none)
 The parameter list tells us what
additional information we need to
complete the job of the method.
Wednesday
 We can have our turtle do turtle
things, like drawing squares and lines
 Or we can have our turtle bring up a
dialog and we can create a picture
from what the user chooses. (This
might be a little strange to have a
turtle do this.)
Wednesday
 Java source code files contain class
definitions, that’s why there is code
that says
public class Name
Wednesday
 In DrJava, comments in files come up
green. Comments are parts of the
file added by the programmer to
explain what the code does. They are
usually written in English (or some
other natural language) and are
ignored by the compiler.
Wednesday
 At the top of the file before the part
where it tells us to add in our own
method definitions, we see the
definitions of the constructors for the
class. Remember, we call the
constructors with new when we are
creating an object.
Friday
 Pictures are made up of a grid of
pixels.
 Each pixel is encoded as a triple of
numbers that represent the amount
of red, green, and blue the pixel
should display
 RGB values range from 0 to 255.
 We can display over 16 million
different colors with this encoding.
Friday
 We can call explore() on a picture
object to allow us to zoom in or out,
or see the particular color value at a
pixel location.
 We can get a Pixel object from a spot
in the Picture grid, and then we can
change its color or even just its red,
green, or blue component.
Download