public boolean isAlive()
return (numLives > 0) ;
public void draw(Graphics2D g2)
Image image = ImageIO. read ( new File( "player.gif" ));
for ( int x=0;x < numLives ; x++)
g2 . drawImage( image , x
IMAGE Y, null );
catch (Exception my)
This chapter introduced the Swing framework in Java. We showed how to create windows
and panels. We also showed how to display text, shapes, and images inside a panel and how
to change the color of drawings. The next chapter shows how the drawings that are inside
a window can react to different events, such as elapsed time period, mouse movement, and
keyboard keys being pressed.
The window class (we usually inherit from it).
The panel class (we usually inherit from it).
Repaints the panel.
Sets the location (top left corner) of the frame to
Makes the frame 200 by 200.
Makes the frame non-resizable. It is resizable by
Makes the frame visible. By default, it is invisible.
frame.setDefaultCloseOperation( ... ); ⇒
The parameter can be EXIT ON CLOSE ,
IDE ON CLOSE , DISPOSE ON CLOSE ,and DO NOTHING ON CLOSE . All parameters are de-
fined as constants in the class JFrame . The method specifies the action that will be
performed when the user tries to close the frame.