Java Reference
In-Depth Information
Thread . sleep ( sleepTime );
} catch
catch ( InterruptedException e ) {
return
return ;
}
}
}
/** paint -- just draw our image at its current location */
public
public void
void paint ( Graphics g ) {
g . drawImage ( img , 0 , 0 , this
this );
}
}
Example 22-6. Bounce.java (part of animator program)
public
public class
class Bounce
Bounce extends
extends Applet implements
implements ActionListener {
private
private static
long serialVersionUID = - 5359162621719520213L ;
/** The main Panel */
protected
static final
final long
protected Panel p ;
/** The image, shared by all the Sprite objects */
protected
protected Image img ;
/** A Vector of Sprite objects. */
protected
protected List < Sprite > v ;
public
public void
void init () {
Button b = new
new Button ( "Start" );
b . addActionListener ( this
this );
setLayout ( new
new BorderLayout ());
add ( b , BorderLayout . NORTH );
add ( p = new
new Panel (), BorderLayout . CENTER );
p . setLayout ( null
null );
String imgName = getParameter ( "imagefile" );
iif ( imgName == null
null ) imgName = "duke.gif" ;
img = getImage ( getCodeBase (), imgName );
MediaTracker mt = new
new MediaTracker ( this
this );
mt . addImage ( img , 0 );
try
try {
mt . waitForID ( 0 );
} catch
catch ( InterruptedException e ) {
throw
throw new
new IllegalArgumentException (
"InterruptedException while loading image " + imgName );
}
iif ( mt . isErrorID ( 0 )) {
throw
throw new
new IllegalArgumentException (
"Couldn't load image " + imgName );
Search WWH ::




Custom Search