-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain2.java
More file actions
78 lines (70 loc) · 1.85 KB
/
main2.java
File metadata and controls
78 lines (70 loc) · 1.85 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
package start;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.BufferStrategy;
import java.lang.reflect.InvocationTargetException;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class main2 {
public static void main(String[]args) {
main2 m = new main2();
m.run();
}
private Animation a;
private ScreenManager s;
private Image bg;
private static final DisplayMode modes1[] = {
new DisplayMode(800,600,32,0),
new DisplayMode(800,600,24,0),
new DisplayMode(800,600,16,0),
new DisplayMode(800,480,32,0),
new DisplayMode(800,480,32,0),
new DisplayMode(800,480,32,0),
};
//load images and add scenes
public void loadImages() {
bg = new ImageIcon("C:\\laks.PNG").getImage();
Image face1 = new ImageIcon("C:\\meme4.PNG").getImage();
Image face2 = new ImageIcon("C:\\meme1.PNG").getImage();
a = new Animation();
a.addScene(face1, 250);
a.addScene(face2, 250);
}
//main method called from main
public void run() {
s = new ScreenManager();
try {
DisplayMode dm = s.findFirstCompatibleMode(modes1);
s.setFullScreen(dm);
loadImages();
movieLoop();
}finally {
s.restoreScreen();
}
}
// play movie
public void movieLoop() {
long startingTime = System.currentTimeMillis();
long cTime = startingTime;
while(cTime-startingTime < 5000) {
long timePassed = System.currentTimeMillis() - cTime;
cTime += timePassed;
a.update(timePassed);
//draw and update screen
Graphics2D g = s.getGraphics();
draw(g);
g.dispose();
s.update();
try {
Thread.sleep(20);
}catch(Exception ex) {
System.out.print("I can't sleep!");
}
}
}
// draws graphics
public void draw(Graphics g) {
g.drawImage(bg, 0, 0, null);
g.drawImage(a.getImage(), 0, 0, null);
}
}