FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaExercises/Experiments/DrawImage.java at master · biblelamp/JavaExercises · GitHub
biblelamp
/
JavaExercises
Public
Notifications
You must be signed in to change notification settings
Fork
130
Star
153
Code
Issues
1
Pull requests
9
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaExercises
/
Experiments
/
DrawImage.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
62 lines (50 loc) · 1.66 KB
Breadcrumbs
JavaExercises
/
Experiments
/
DrawImage.java
Copy path
File metadata and controls
62 lines (50 loc) · 1.66 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
awt
.*;
import
java
.
io
.*;
import
javax
.
imageio
.*;
import
javax
.
swing
.*;
public
class
DrawImage
{
public
static
void
main
(
String
[]
args
) {
EventQueue
.
invokeLater
(
new
Runnable
() {
public
void
run
() {
ImageFrame
frame
=
new
ImageFrame
();
frame
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
frame
.
setVisible
(
true
);
}
});
}
}
class
ImageFrame
extends
JFrame
{
public
ImageFrame
() {
setTitle
(
"ImageTest"
);
setSize
(
DEFAULT_WIDTH
,
DEFAULT_HEIGHT
);
// adding a component to the frame
ImageComponent
component
=
new
ImageComponent
();
add
(
component
);
}
public
static
final
int
DEFAULT_WIDTH
=
300
;
public
static
final
int
DEFAULT_HEIGHT
=
300
;
}
class
ImageComponent
extends
JComponent
{
private
Image
image
;
public
ImageComponent
() {
// get image (from http://iconbird.com/)
try
{
image
=
ImageIO
.
read
(
new
File
(
"ball.png"
));
}
catch
(
IOException
e
) {
e
.
printStackTrace
();
}
}
public
void
paintComponent
(
Graphics
g
) {
if
(
image
==
null
)
return
;
int
imageWidth
=
image
.
getWidth
(
this
);
int
imageHeight
=
image
.
getHeight
(
this
);
// displays the image in the upper left corner
g
.
drawImage
(
image
,
0
,
0
,
null
);
// multiple image display panel
for
(
int
i
=
0
;
i
*
imageWidth
<=
getWidth
();
i
++)
for
(
int
j
=
0
;
j
*
imageHeight
<=
getHeight
();
j
++)
if
(
i
+
j
>
0
)
g
.
copyArea
(
0
,
0
,
imageWidth
,
imageHeight
,
i
*
imageWidth
,
j
*
imageHeight
);
}
}
Back
|
FazBrowse Home
|
New Git URL