Repository navigation
Expand file tree
/
Copy pathStartUp.java
More file actions
113 lines (90 loc) · 3.28 KB
/
Copy pathStartUp.java
File metadata and controls
113 lines (90 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
import javax.sound.sampled.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
/**
* Start menu GUI
* - Play button
* - How to play - showing user controls */
public class StartUp implements ActionListener {
JButton play;
JButton howToPlay;
private HowToPlay howToPlayWindow;
private SelectStadium selectStadium;
private Clip clip;
// CONSTRUCTOR
public StartUp() {
// MUSIC
try {
music();
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
e.printStackTrace();
}
final JFrame frame = new JFrame("Soccer Head");
JPanel panel = new JPanel();
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
frame.setLocationByPlatform(true);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
panel.setLayout(null);
// PLAY button
play = new JButton("PLAY");
play.setBounds(0, 150, 200, 100);
// HOW TO PLAY button
howToPlay = new JButton("How to play");
howToPlay.setBounds(0, 250, 200, 100);
panel.add(play);
panel.add(howToPlay);
// ball gif
ImageIcon ballImg = new ImageIcon("data/balls/bouncingBall.gif");
JLabel ball = new JLabel("",ballImg,JLabel.CENTER);
ball.setBounds(0,0,700,575);
panel.add(ball);
// header
ImageIcon textImg = new ImageIcon("data/text/header.png");
JLabel text = new JLabel("",textImg,JLabel.CENTER);
text.setBounds(0,0,500,150);
panel.add(text);
//background
ImageIcon img = new ImageIcon("data/stadiums/grass.png");
JLabel background = new JLabel("",img,JLabel.CENTER);
background.setBounds(0,0,500,500);
panel.add(background);
frame.setVisible(true);
// allow button usability
buttonListeners();
}
public void buttonListeners() {
ActionListener playButton = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// if player selects PLAY, they then get to select a stadium
selectStadium = new SelectStadium();
clip.stop();
}
};
ActionListener howToPlayButton = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// opens new window showing users how to play
howToPlayWindow = new HowToPlay();
}
};
play.addActionListener(playButton);
howToPlay.addActionListener(howToPlayButton);
}
@Override
public void actionPerformed(ActionEvent e) {
}
public void music() throws UnsupportedAudioFileException, IOException, LineUnavailableException {
File music = new File("data/sounds/music.wav");
AudioInputStream audioStream = AudioSystem.getAudioInputStream(music);
clip = AudioSystem.getClip();
clip.open(audioStream);
clip.start();
}
}