-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayFileLoading.java
More file actions
146 lines (126 loc) · 4.86 KB
/
PlayFileLoading.java
File metadata and controls
146 lines (126 loc) · 4.86 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//************************************************************************
// File: PlayFileLoading.java CPSC-112 CLASS PROJECT
//
// Author: Hanah Leventhal Email: hanah.leventhal@yale.edu
//
// Class: PlayFileLoading
// Dependencies: GuitarHeroAutoAltered
//
// --------------------
//
// This program sets up the record button loading page GUI. There is a
// frame containing the menu, title, extra text, and progress bar. The
// progress bar progresses incrementally via a timer and calls the
// GuitarHeroAutoAltered playFile method when it reaches 100.
//
//************************************************************************
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.util.Timer;
public class PlayFileLoading {
private static final Color YaleBlue = new Color(0, 53, 107);
public static final String frameIconImage = "songgeneratoricon.PNG";
private static int count = 0;
public static JFrame loadingScreenGUI(JFrame frame, JTextField fileNameInput, String musicFileName) {
// Clear frame
frame.getContentPane().removeAll();
frame.setBackground(YaleBlue);
frame.setLayout(new BorderLayout());
//Set the frame icon to an image loaded from a file.
frame.setIconImage(new ImageIcon(frameIconImage).getImage());
// Add MenuBar to frame
JMenuBar menuBar = Menu.menuBarGUI(frame);
frame.add(menuBar, BorderLayout.NORTH);
// Create contentPanel
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new GridLayout(2,1));
contentPanel.setBackground(YaleBlue);
frame.add(contentPanel, BorderLayout.CENTER);
// Create titlePanel
JPanel titlePanel = new JPanel();
titlePanel.setLayout(new GridLayout(2,1));
titlePanel.setBackground(YaleBlue);
contentPanel.add(titlePanel);
// Page title
JLabel title = new JLabel("<html><ceneter>Preparing Song...</center></html>", SwingConstants.CENTER){
public Dimension getPreferredSize() {
return new Dimension(500, 125);
}
public Dimension getMinimumSize() {
return new Dimension(500, 125);
}
public Dimension getMaximumSize() {
return new Dimension(1920, 200);
}
};
// Create font size
Font font3 = new Font("SansSerif", Font.BOLD, 100);
title.setFont(font3);
title.setForeground(Color.WHITE);
JLabel extraText = new JLabel("<html><ceneter>Please wait.</center></html>", SwingConstants.CENTER){
public Dimension getPreferredSize() {
return new Dimension(500, 125);
}
public Dimension getMinimumSize() {
return new Dimension(500, 125);
}
public Dimension getMaximumSize() {
return new Dimension(1920, 200);
}
};
// Create font size
Font font4 = new Font("SansSerif", Font.BOLD, 50);
extraText.setFont(font4);
extraText.setForeground(Color.WHITE);
titlePanel.add(title);
titlePanel.add(extraText);
// Create loadingBarPanel
JPanel loadingBarPanel = new JPanel();
loadingBarPanel.setLayout(new GridLayout(3,3));
loadingBarPanel.setBackground(YaleBlue);
contentPanel.add(loadingBarPanel);
// Create progress bar
JProgressBar progressBar = new JProgressBar(0, 100);
progressBar.setValue(0);
progressBar.setStringPainted(true);
// Timed increase of progress bar
int delay = 250; // delay for 1 sec.
int period = 175; // repeat every sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask()
{
public void run(){
if (progressBar.getValue() == 100) {
progressBar.setValue(100);
JFrame frame2;
frame2 = GuitarHeroAutoAltered.playFile(frame, musicFileName);
// set the text of field to blank
fileNameInput.setText("FileName.txt");
GuitarHeroAutoAltered.playFileGUI(frame2);
count = 0;
progressBar.setValue(0);
timer.cancel();
}
else {
progressBar.setValue(count * 5);
count++;
}
}
}, delay, period);
// Add to loadingBarPanel
loadingBarPanel.add(new JLabel(""));
loadingBarPanel.add(new JLabel(""));
loadingBarPanel.add(new JLabel(""));
loadingBarPanel.add(new JLabel(""));
loadingBarPanel.add(progressBar);
loadingBarPanel.add(new JLabel(""));
loadingBarPanel.add(new JLabel(""));
loadingBarPanel.add(new JLabel(""));
loadingBarPanel.add(new JLabel(""));
// Repaint new content
frame.revalidate();
frame.repaint();
return frame;
}
}