-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplash.java
More file actions
123 lines (104 loc) · 3.28 KB
/
Splash.java
File metadata and controls
123 lines (104 loc) · 3.28 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
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Splash {
/**
* Splash class of Slide Into Highschool, creates splashscreen that is animated
*
* <h2>Course Info:</h2>
* ICS4UP with Krasteva, V.
* Date: June 8th, 2023
* Time Spent: 0.5 hrs
* @version 1
* @author Charlie To, Milena Mofrad
*/
JFrame frame;
/**
* Constructor method
*
* @param frame Takes JGrasp frame
*/
public Splash(JFrame fr) {
this.frame = fr;
this.frame.revalidate();
this.frame.repaint();
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new MyPane());
frame.pack();
frame.setVisible(true);
}
});
}
public class MyPane extends JPanel {
private int x = 0;
private int y = 0;
Timer timer;
/* I learned how to use a timer using GeeksForGeeks.org
https://www.geeksforgeeks.org/java-util-timer-class-java/
*/
/**
* MyPane method, starts timer
*/
public MyPane() {
timer = new Timer(10, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
move();
repaint();
}
});
timer.start();
}
/**
* Changes variables
*/
protected void move() {
x++;
y--;
if(x>300){
timer.stop();
}
}
@Override
public Dimension getPreferredSize() {
return new Dimension(800, 500);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Colours.backgroundBlue);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.WHITE);
g.setFont(Colours.largeSerifFont);
g.drawString("Slide Into", 0+x,200);
g.drawString("High School", 580+y,300);
g.setColor(new Color(230,190,30));//yellow
g.fillRect(0,400,800,100);
g.setColor(new Color(100,50,0));//dark brown
g.fillRect(90,-100+x,20,200);
g.setColor(new Color(150,70,0));//light brown
g.fillRect(50,40+x,100,60);
g.setColor(new Color(50,200,100));//green
g.fillOval(50,-250+x,100,100);
g.fillOval(50,-170+x,100,100);
g.fillOval(50,-90+x,100,100);
g.setColor(new Color(100,50,0));//dark brown
g.fillRect(690,-100+x,20,200);
g.setColor(new Color(150,70,0));//light brown
g.fillRect(650,40+x,100,60);
g.setColor(new Color(50,200,100));//green
g.fillOval(650,-250+x,100,100);
g.fillOval(650,-170+x,100,100);
g.fillOval(650,-90+x,100,100);
g.dispose();
}
}
}