Java Reference
In-Depth Information
LISTING 9.16
//********************************************************************
// ReboundPanel.java Author: Lewis/Loftus
//
// Represents the primary panel for the Rebound program.
//********************************************************************
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ReboundPanel extends JPanel
{
private final int WIDTH = 300, HEIGHT = 100;
private final int DELAY = 20, IMAGE_SIZE = 35;
private ImageIcon image;
private Timer timer;
private int x, y, moveX, moveY;
//-----------------------------------------------------------------
// Sets up the panel, including the timer for the animation.
//-----------------------------------------------------------------
public ReboundPanel()
{
timer = new Timer(DELAY, new ReboundListener());
image = new ImageIcon ("happyFace.gif");
x = 0;
y = 40;
moveX = moveY = 3;
setPreferredSize ( new Dimension(WIDTH, HEIGHT));
setBackground (Color.black);
timer.start();
}
//-----------------------------------------------------------------
// Draws the image in the current location.
//-----------------------------------------------------------------
public void paintComponent (Graphics page)
{
super .paintComponent (page);
image.paintIcon ( this , page, x, y);
}
Search WWH ::




Custom Search