This repository was archived by the owner on Jul 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIntroGui.java
More file actions
136 lines (132 loc) · 5.09 KB
/
Copy pathIntroGui.java
File metadata and controls
136 lines (132 loc) · 5.09 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
package com.company;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import javafx.embed.swing.JFXPanel;
import javafx.scene.media.*;
public class IntroGui {
private JFrame mainframe;
private JLabel headerLabel;
private JLabel StatusLabul;
private JPanel controlpanel;
MediaPlayer mediaplayer;
public IntroGui() throws URISyntaxException, IOException {
JFXPanel fxpanel = new JFXPanel();
prepareGUI();
}
private void prepareGUI() throws URISyntaxException, IOException {
mainframe = new JFrame("Tic-Tac-Toe");
mainframe.setSize(400,400);
mainframe.setBackground(Color.BLACK);
mainframe.setLayout(new GridLayout(3,1));
headerLabel = new JLabel("",JLabel.CENTER);
StatusLabul = new JLabel("",JLabel.CENTER);
StatusLabul.setForeground(Color.RED);
StatusLabul.setText("TIC-TAC-TOE");
StatusLabul.setFont(new Font("Sans",Font.ITALIC,30));
StatusLabul.setSize(350,350);
StatusLabul.setLayout(new BorderLayout());
mainframe.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
controlpanel = new JPanel();
controlpanel.setLayout(new FlowLayout());
mainframe.getContentPane().setBackground(Color.DARK_GRAY);
headerLabel.setOpaque(false);
StatusLabul.setOpaque(false);
mainframe.add(headerLabel);
mainframe.add(StatusLabul,BorderLayout.NORTH);
mainframe.add(controlpanel);
mainframe.setVisible(true);
String bip = "song.mp3";
Media hit = new Media(Paths.get(bip).toUri().toString());
mediaplayer = new MediaPlayer(hit);
mediaplayer.play();
}
public void showEvents() {
controlpanel.setLayout(new BorderLayout());
controlpanel.setOpaque(true);
JButton Startbutton = new JButton("Start Game");
JButton mute = new JButton("Mute");
JPanel buttonpanel = new JPanel();
JButton exitButton = new JButton("Exit");
Startbutton.setActionCommand("Start Game");
Startbutton.setBorderPainted(false);
Startbutton.setContentAreaFilled(false);
Startbutton.setFocusPainted(false);
Startbutton.setOpaque(true);
mute.setActionCommand("Mute");
mute.setBorderPainted(false);
mute.setContentAreaFilled(false);
mute.setFocusPainted(false);
mute.setOpaque(true);
exitButton.setActionCommand("Exit");
exitButton.setBorderPainted(false);
exitButton.setContentAreaFilled(true);
exitButton.setFocusPainted(false);
exitButton.setOpaque(true);
Startbutton.setBackground(Color.WHITE);
exitButton.setBackground(Color.WHITE);
mute.setBackground(Color.WHITE);
JButton play = new JButton("Play");
play.setActionCommand("Play");
play.setBorderPainted(false);
play.setContentAreaFilled(false);
play.setFocusPainted(false);
play.setOpaque(true);
play.setBackground(Color.WHITE);
Startbutton.addActionListener(new ButtonClickListener());
mute.addActionListener(new ButtonClickListener());
exitButton.addActionListener(new ButtonClickListener());
buttonpanel.setLayout(new FlowLayout(FlowLayout.CENTER));
play.addActionListener(new ButtonClickListener());
buttonpanel.add(Startbutton);
buttonpanel.add(exitButton);
buttonpanel.add(mute);
buttonpanel.add(play);
buttonpanel.setBackground(Color.DARK_GRAY);
controlpanel.add(buttonpanel,BorderLayout.NORTH);
controlpanel.setBackground(Color.DARK_GRAY);
mainframe.setVisible(true);
}
private class ButtonClickListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if(command.equals("Start Game"))
{
StatusLabul.setText("Game initialized");
mainframe.dispose();
mediaplayer.dispose();
try {
GameStartGui s = new GameStartGui();
s.showEvents();
} catch (URISyntaxException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if(command.equals("Mute"))
{
mediaplayer.setMute(true);
}
if(command.equals("Exit"))
{
System.exit(0);
}
if(command.equals("Play"))
{
mediaplayer.setMute(false);
}
}
}
}