-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.java
More file actions
69 lines (52 loc) · 1.35 KB
/
Main.java
File metadata and controls
69 lines (52 loc) · 1.35 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Intro extends JComponent {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.LIGHT_GRAY);
g.drawLine(0,400 , 800, 400);
g.drawRect(90, 370, 30, 30);
g.fillRect(90,370,30,30);
g.setColor(Color.BLACK);
g.setFont(g.getFont().deriveFont(g.getFont().getSize() * 2.0F));
g.drawString("Press Any Key to Start", 275, 285);
}
}
public class Main {
static JFrame frame;
static boolean gameplaying = false;
Main() {
frame = new JFrame();
frame.setSize(800,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new Intro());
frame.addKeyListener(new KeyListener(){
@Override
public void keyTyped(KeyEvent arg0) {
}
@Override
public void keyReleased(KeyEvent arg0) {
}
@Override
public void keyPressed(KeyEvent arg0) {
if(!gameplaying && Game.gameOver)
System.exit(1);
if(!gameplaying) {
frame.getContentPane().removeAll();
new Game();
}
}
});
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
new Main();
}
});
}
}