-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
62 lines (49 loc) · 1.75 KB
/
Main.java
File metadata and controls
62 lines (49 loc) · 1.75 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main extends JFrame {
PlayPanel playPanel;
public Main() {
setTitle("<Tetris>");
setLayout(new BorderLayout(10, 10));
playPanel = new PlayPanel();
add("Center", playPanel);
JButton startPauseButton, exitButton;
startPauseButton = new JButton("Pause");
exitButton = new JButton("Exit");
JPanel gridPanel = new JPanel(new GridLayout(1, 3, 10, 10));
gridPanel.add(startPauseButton);
gridPanel.add(exitButton);
JPanel buttonPanel = new JPanel();
buttonPanel.add(gridPanel);
add("South", buttonPanel);
startPauseButton.addActionListener(e -> {
JButton button = (JButton) e.getSource();
if (playPanel.isPause()) {
button.setText("Pause");
playPanel.resume();
playPanel.requestFocus();
} else {
button.setText("Start");
playPanel.pause();
}
});
exitButton.addActionListener(e->{
startPauseButton.setText("Start");
playPanel.pause();
int confirm = JOptionPane.showConfirmDialog(null,
"really?", "tetris", JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
System.exit(0);
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize((int) (PlayPanel.mGetWidth() * 1.2), (int) (PlayPanel.mGetHeight() * 1.2));
System.out.println(getSize());
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}