CIS525 - Lecture#12 - October 16, 2000
CIS 525 10/16/00
Exception handling
------------------
Syntax:
try{
statement1;
statement2;
|
|
}
catch(SomeException someVar); { <==this will 'capture' the exception
handle Exception(someVar);
}
-can have mult catch exceptions
-can have a 'finally' clause, like a 'default' in 'switch' statement
page 353-ish
public
someType some method()
throws SomeException { // exception is called
throw IOException() // IOException called
END OF CHAPTER 8
Applets:
1) can not read files from local hard disk
2) can not write to local hard drives, (except for cookies)
3) maynot open network to servers other then where applet came from
4) can not call local programs
5) can not discover private info re: users, only connections
Java applet template, page 359
import Java.applet.Applet;
imprort Java.awt.*;
public class AppletTemp extends Applet{
public void init() {
public void paint(Graphics g) {
html template:
NOTE: paint ONLY re-draws what is in current clipping window
repaint() will display all
Clip.html re-draws clipping window
page 371
public void init() // initialize variables
public void start() // called after init(), before paint()
public void paint() // user drawing
public void stop() // exited or minimized
public void destroy() // when app is permanently shut down
page 383, read a parameter that is passed in html tag
HelloWWW2.html, passes background color as a parameter
see JavaJump2
// This honors requests to quit the window
public boolean handleEvent)Event event) {
if(event.id == Event.WINDOW_DESTROY)
Systm.exit(o);
return(super.handleEvent(event));
}
}
page 388
getGraphics() // for all graphics, you must call this
page 392-423, graphics stuff
i.e, how to have multiple widths on pen
page 424, loading and drawing images from inside of Java:
1) first image must be 'registered' using getImage() from the Java library, (Applet or Toolkit)
2) image is drawn using drawImage from graphics, (.jpg, .gif)
getImage => requires two strings as arguments
1) directory //use getCodeBase() or getDocument base to supply directory name
2) file name
see page 426 JavaMan1.java for a example of above image manipulation
drawImage(image, left, top, window); //'window' is normally 'this'
drawImage(image, left, top, width, height, window); //'window' is normally 'this'
page 434-7, pre-load images for quicker loading
page 439-47, BetterImageBox.html, draws frame around an image by using 'MediaTracker'
and 'waitForAll'. Otherwise, the app doesn't have the images completely loaded and the
size of the frame is unknown
end of chapter 9