Page 717 - Introduction to Programming with Java: A Problem Solving Approach
P. 717
16.18 Mouse Listeners and Images (Optional) 683
/********************************************************
*
DragSmiley.java
Dean & Dean
This program displays a smiley face image.
When the user presses the mouse, the image changes to a
scared image. The user can drag the image.
********************************************************/
*
*
*
*
*
import javax.swing.*;
public class DragSmiley extends JFrame
{
}
// end class DragSmiley
private static final int WIDTH = 250;
private static final int HEIGHT = 250;
private SmileyPanel smileyPanel;
// drawing panel
//*****************************************************
public DragSmiley()
{
setTitle("Drag Smiley");
setSize(WIDTH, HEIGHT);
setDefaultCloseOperation(EXIT_ON_CLOSE);
smileyPanel = new SmileyPanel();
Apago PDF Enhancer
setVisible(true);
// end DragSmiley constructor
//**************************************
}
}
add(smileyPanel);
public static void main(String[] args)
{
new DragSmiley();
Initial display: While dragging smiley: After releasing mouse button:
Figure 16.16 Driver class and sample output for the DragSmiley program