-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFramesAndImages_UsingGraphics.java
More file actions
executable file
·84 lines (63 loc) · 1.77 KB
/
FramesAndImages_UsingGraphics.java
File metadata and controls
executable file
·84 lines (63 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// The "FramesAndImages" class.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;
public class FramesAndImages_UsingGraphics extends JPanel implements MouseListener
{
JLabel picLabel, message;
int imageNo;
Image [] images;
public FramesAndImages_UsingGraphics ()
{
setPreferredSize(new Dimension(400, 400));
images = new Image [5];
for (int imageNo = 0 ; imageNo < 5 ; imageNo++)
{
String imageFileName = "pic" + imageNo + ".gif";
images [imageNo]= Toolkit.getDefaultToolkit().getImage(imageFileName);
}
//contentPane = new JPanel ();
setLayout (new BoxLayout (this, BoxLayout.PAGE_AXIS));
setBackground (Color.white);
setBorder (BorderFactory.createEmptyBorder (10,10,10,10));
message = new JLabel ("Image #" + (imageNo + 1));
add (message);
addMouseListener (this);
} // Constructor
public void mouseClicked (MouseEvent e)
{
imageNo++;
if (imageNo > 4)
imageNo = 0;
repaint ();
}
public void mouseReleased (MouseEvent e)
{
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
public void mousePressed(MouseEvent arg0) {
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawImage (images[imageNo],10,10,this);
message.setText ("Image #" + (imageNo + 1));
//g.finalize();
}
public static void main (String [] args){
JFrame frame = new JFrame ("Displaying Images"); // Set the frame's name
FramesAndImages_UsingGraphics myPanel = new FramesAndImages_UsingGraphics ();
frame.add(myPanel);
frame.pack();
frame.setVisible(true);
}
}