-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.java
115 lines (93 loc) · 3.11 KB
/
View.java
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
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.event.*;
/**
* View
*/
public class View extends JPanel {
int width = 1200;
int height = 800;
int frame = 0;
private Plane plane;
private Clouds clouds;
private Sky sky;
private BufferedImage planeIcon;
private boolean flyAway = false;
View() {
JFrame frame = new JFrame() {
@Override
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
ourExit();
}
};
};
frame.add(this);
frame.setSize(width, height);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setBackground(new Color(128, 217, 255));
// Inicializimi i objekteve
plane = new Plane(-width / 2, 0, width / 10, width);
planeIcon = plane.getPlaneIcon();
sky = new Sky(width, height);
clouds = new Clouds(width, height);
frame.setVisible(true);
}
@Override
public void paint(Graphics g) {
// Properties te g
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
BasicStroke stroke = new BasicStroke(10);
g2.setColor(Color.red);
g2.setStroke(stroke);
// Ndrimi i dites
sky.changeTime(g2);
g2.translate(width / 2, height / 2);
// Vizatimi i Aeroplanit
plane.movePlane();
if (flyAway) {
plane.flyAway();
}
AffineTransform planeMove = new AffineTransform();
planeMove.translate(plane.getX(), plane.getY());
// planeMove.scale(1.2, 1.2); plane 1
planeMove.scale(0.9, 0.9);
g2.drawImage(planeIcon, planeMove, null);
// Vizatimi i reve
// Nese nuk eshte nate, mos vizato re
Cloud[] clouds_arr = clouds.getClouds();
if (sky.isNight()) {
clouds.noMoreClouds();
} else {
clouds.moveAll();
for (Cloud cloud : clouds_arr) {
AffineTransform cloudTransform = new AffineTransform();
cloudTransform.translate(cloud.getX(), cloud.getY());
cloudTransform.scale(cloud.getScale(), cloud.getScale());
g2.drawImage(cloud.getImage(), cloudTransform, null);
}
}
// Frame updates
try {
Thread.sleep(5);
} catch (Exception e) {
}
repaint();
}
void ourExit() {
flyAway = true;
if (!plane.flewAway()) {
JOptionPane.showMessageDialog(this, "Shpresojme se keni pasur nje udhetim te mbare",
"Grupi_D Airlines",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
ourExit();
}
}
}