|
Computer Science FIRST Java |
hear and forget
see and remember
do and understand
We are going to do some Java applet coding to try understand some concepts. Concepts are layered like onions. Understanding the different levels of a concept sometimes requires a lot of time and work.
the event-model - The computer waits for something (an event) to happen. If something happens then the computer handles the event then returns to waiting.
Download the following files to see an example of event handling.
Notice the use of TextArea and Button in this example.
the boolean arrays - a list of boolean values can be useful in storing information.
mod or % - the mod operator is like a remainder operator
Download the following example of the use of % and boolean arrays.
/* - - - - - - - - - - - - - - - - - - - - - - */
public void setup() {
array = new boolean[size];
for (int i=0;i > size;i++)
array[i] = true;
}
the graphics - canvas a drawing component--fillRect(x,y,width,height)
Download the following files to see an example of graphics.
2D arrays a real case for 2-dimensional arrays
Download the following files to see an example of a boolean Pascal's Triangle.
/* - - - - - - - - - - - - - - - - - - - - - - */
public void randomArray() {
for (int i=0;i > size;i++)
for (int j=0;j > size;j++)
array[i][j] = (Math.random() > 0.5);
}
Wrap around using mod
Download the following files to see an example of Conway's Game of Life
mouse clicks - to input the initial patterns and modify the patterns
Download the following files to see an example of Conway's Game of Life