Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPictureFrame.java
More file actions
Latest commit
executable file
·175 lines (143 loc) · 3.72 KB
/
Copy pathPictureFrame.java
File metadata and controls
executable file
·175 lines (143 loc) · 3.72 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
importjavax.swing.*;
importjava.awt.*;
/**
* Class that holds a digital picture and displays it using a JFrame
*
* @author Barb Ericson
*/
publicclassPictureFrame
{
////////////////// fields ////////////////////////////
/** Main window used as the frame */
JFrameframe = newJFrame();
/** ImageIcon used to display the picture in the label*/
ImageIconimageIcon = newImageIcon();
/** Label used to display the picture */
privateJLabellabel = newJLabel(imageIcon);
/** Digital Picture to display */
privateDigitalPicturepicture;
///////////////// constructors ////////////////////////
/**
* A constructor that takes no arguments. This is needed
* for subclasses of this class
*/
publicPictureFrame()
{
// set up the frame
initFrame();
}
/**
* A constructor that takes a picture to display
* @param picture the digital picture to display in the
* picture frame
*/
publicPictureFrame(DigitalPicturepicture)
{
// set the current object's picture to the passed in picture
this.picture = picture;
// set up the frame
initFrame();
}
///////////////////////// methods ///////////////////////////////
/**
* Method to set the picture to show in this picture frame
* @param picture the new picture to use
*/
publicvoidsetPicture(Picturepicture)
{
this.picture = picture;
imageIcon.setImage(picture.getImage());
frame.pack();
frame.repaint();
}
/**
* A method to update the picture frame image with the image
* in the picture
*/
publicvoidupdateImage()
{
// only do this if there is a picture
if (picture != null)
{
// set the image for the image icon from the picture
imageIcon.setImage(picture.getImage());
// set the title of the frame to the title of the picture
frame.setTitle(picture.getTitle());
}
}
/**
* A method to update the picture frame image with the image in
* the picture and show it
*/
publicvoidupdateImageAndShowIt()
{
// first update the image
updateImage();
// now make sure it is shown
frame.setVisible(true);
}
/**
* A method to make sure the frame is displayed
*/
publicvoiddisplayImage()
{
frame.setVisible(true);
}
/**
* A method to hide the frame
*/
publicvoidhide()
{
frame.setVisible(false);
}
/**
* A method to set the visible flag on the frame
* @param flag the flag to use
*/
publicvoidsetVisible(booleanflag)
{
frame.setVisible(flag);
}
/**
* A method to close a picture frame
*/
publicvoidclose()
{
frame.setVisible(false);
frame.dispose();
}
/**
* Method to set the title for the picture frame
* @param title the title to use
*/
publicvoidsetTitle(Stringtitle)
{
frame.setTitle(title);
}
/**
* Method to force the picture frame to repaint (redraw)
*/
publicvoidrepaint()
{
// make it visible
frame.setVisible(true);
// update the image from the picture
updateImage();
// tell the JFrame to handle the repaint
frame.repaint();
}
/**
* A method to initialize the picture frame
*/
privatevoidinitFrame()
{
// set the image for the picture frame
updateImage();
// add the label to the frame
frame.getContentPane().add(label);
// pack the frame (set the size to as big as it needs to be)
frame.pack();
// make the frame visible
frame.setVisible(true);
}
}