FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programming-Exercises/SimpleAnimation.java at master · RoyTien/Java-Programming-Exercises · GitHub
RoyTien
/
Java-Programming-Exercises
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Programming-Exercises
/
SimpleAnimation.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
59 lines (44 loc) · 1.27 KB
Breadcrumbs
Java-Programming-Exercises
/
SimpleAnimation.java
Copy path
File metadata and controls
59 lines (44 loc) · 1.27 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
import
javax
.
swing
.*;
import
java
.
awt
.*;
public
class
SimpleAnimation
{
int
x
=
70
;
int
y
=
70
;
public
static
void
main
(
String
[]
args
){
SimpleAnimation
gui
=
new
SimpleAnimation
();
gui
.
go
();
}
public
void
go
(){
JFrame
frame
=
new
JFrame
();
frame
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
MyDrawPanel
drawPanel
=
new
MyDrawPanel
();
frame
.
getContentPane
().
add
(
drawPanel
);
frame
.
setSize
(
600
,
600
);
frame
.
setVisible
(
true
);
for
(
int
i
=
0
;
i
<
400
;
i
++){
x
++;
y
++;
drawPanel
.
repaint
();
try
{
Thread
.
sleep
(
50
);
}
catch
(
Exception
ex
){ }
}
}
class
MyDrawPanel
extends
JPanel
{
public
void
paintComponent
(
Graphics
g
){
Graphics2D
g2d
= (
Graphics2D
)
g
;
g
.
setColor
(
Color
.
white
);
g
.
fillRect
(
0
,
0
,
this
.
getWidth
(),
this
.
getHeight
());
int
myRed
= (
int
)(
Math
.
random
() *
255
);
int
myGreen
= (
int
)(
Math
.
random
() *
255
);
int
myBlue
= (
int
)(
Math
.
random
() *
255
);
Color
startColor
=
new
Color
(
myRed
,
myGreen
,
myBlue
);
myRed
= (
int
)(
Math
.
random
() *
255
);
myGreen
= (
int
)(
Math
.
random
() *
255
);
myBlue
= (
int
)(
Math
.
random
() *
255
);
Color
endColor
=
new
Color
(
myRed
,
myGreen
,
myBlue
);
GradientPaint
gradient
=
new
GradientPaint
(
70
,
70
,
startColor
,
150
,
150
,
endColor
);
g2d
.
setPaint
(
gradient
);
g2d
.
fillOval
(
x
,
y
,
100
,
100
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL