Tom Kelliher, CS 116
Nov. 17, 2000
Finish GalaEvents part of Lab 6 by start of class, Monday after Thanksgiving. Don't submit anything yet.
Lab 6.
Exam.
Four concept questions: events, boolean and comparison expressions, variables and scope, parameters and return values.
Two code writing questions: write a class (similar to last quiz), write a small applet (event handling).
return
statement. A method's return type.
public void caller() { int answer, b = 5, c = 12; answer = callee(b, c / b + 5); } public int callee(int i, int j) { if (i > j) return i - j; else if (i < j) return return j - i; else return -1; }Assume that execution begins in
caller()
. What values are
assigned to i
, j
, and answer
? Answer: 5, 7, and 2.
Try with different values of b
and c
.
// Instance variables: int a = 1, b = 2, c = 3; public void method1() { int a = 0, b = 4; a = method2(b, a * c); } public int method2(int a, int b) { int c = 5; return a + b + c; {Assume that execution begins in
method1()
. What value is
assigned to a
in method1()
? Determining the values
assigned to method2()
's formal parameters will help.
!
, &&
||
.
<
, <=
, >
, >=
,
==
, !=
.
if
statement.
import java.awt.event.*;
implements XXXListener
source.addXXXListener(listener);
public void actionPerformed(ActionEvent e) { // Code to deal with each source's event must be included // here. The code will have to determine which source generated // the event. }
EtchASketch.java
http://phoenix.goucher.edu/~kelliher/f2000/cs116/applets/EtchASketch.java
).
Applet
, ActionListener
, String
,
ActionEvent
.
Button
, Label
setBackground()
, setForeground()
, setText()
.
add()
, addActionListener()
,
actionPerformed()
, getActionCommand()
.
equals()
.