-
Notifications
You must be signed in to change notification settings - Fork 2
/
TetrisViewer.java
58 lines (48 loc) · 1.6 KB
/
TetrisViewer.java
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
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.event.*;
/**
* Viewer class that creates and displays the window for the Tetris game
*
* @author gcschmit
* @version 24 January 2020
*/
public class TetrisViewer
{
/**
* Creates a window, installs the JTetris or JBrainTetris, checks the
* testMode state, install the controls in the EAST.
*/
public static void main(String[] args)
{
JFrame frame = new JFrame("Tetris 2020");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComponent container = (JComponent)frame.getContentPane();
container.setLayout(new BorderLayout());
final int PIXELS = 16;
JTetris tetris = new JTetris((JTetris.WIDTH * PIXELS) + 2,
(JTetris.HEIGHT + JTetris.TOP_SPACE) * (PIXELS + 2));
container.add(tetris, BorderLayout.CENTER);
if (args.length != 0 && args[0].equals("test"))
{
tetris.testMode = true;
}
Container panel = tetris.createControlPanel();
// Add the quit button last so it's at the bottom
panel.add(Box.createVerticalStrut(12));
JButton quit = new JButton("Quit");
panel.add(quit);
quit.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
container.add(panel, BorderLayout.EAST);
frame.pack();
frame.setVisible(true);
}
}