Skip to content

Commit b584589

Browse files
committed
Fixed issue with wrong WindowConstant
1 parent a039837 commit b584589

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

src/main/dev/lh/Viewport.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Project: <strong>Snake</strong><br>
1313
* File: <strong>Viewport.java</strong><br>
1414
* Created: <strong>01.07.2020</strong><br>
15-
*
15+
*
1616
* @author Kai S. K. Engelbart
1717
* @since Snake 1.2
1818
*/
@@ -42,24 +42,22 @@ public Viewport(Updateable gameRoot) {
4242

4343
/**
4444
* Starts the render task.
45-
*
45+
*
4646
* @since Snake 1.2
4747
*/
4848
public void start() {
49-
if (renderTask != null)
50-
renderTask.cancel();
51-
else
52-
createBufferStrategy(2);
49+
if (renderTask != null) renderTask.cancel();
50+
else createBufferStrategy(2);
5351

5452
renderTask = new TimerTask() {
5553

56-
private long lastTime = System.currentTimeMillis();
54+
// private long lastTime = System.currentTimeMillis();
5755

5856
@Override
5957
public void run() {
60-
long time = System.currentTimeMillis();
61-
double dt = (time - lastTime) * 1E-3;
62-
lastTime = time;
58+
// final long time = System.currentTimeMillis();
59+
// final double dt = (time - lastTime) * 1E-3;
60+
// lastTime = time;
6361
// TODO: Delta time adjustment
6462
gameRoot.tick();
6563
render();
@@ -71,15 +69,13 @@ public void run() {
7169

7270
/**
7371
* Stops the render task.
74-
*
72+
*
7573
* @since Snake 1.2
7674
*/
77-
public void stop() {
78-
renderTask.cancel();
79-
}
75+
public void stop() { renderTask.cancel(); }
8076

8177
private void render() {
82-
Graphics2D g = (Graphics2D) getBufferStrategy().getDrawGraphics();
78+
final Graphics2D g = (Graphics2D) getBufferStrategy().getDrawGraphics();
8379

8480
// Clear the screen
8581
g.setColor(Color.BLACK);

src/main/dev/lh/ui/Endscreen.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,25 @@ public class Endscreen extends JDialog {
3232
public Endscreen(int score) {
3333
this.score = score;
3434
setTitle("Endscreen");
35-
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
35+
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
3636
setBounds(100, 100, 700, 700);
3737
getContentPane().setLayout(new BorderLayout());
3838
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
3939
contentPanel.setLayout(new BorderLayout(0, 0));
4040
getContentPane().add(contentPanel, BorderLayout.CENTER);
4141

42-
JButton btnNewButton = new JButton("Play again");
42+
final JButton btnNewButton = new JButton("Play again");
4343
btnNewButton.setMnemonic(KeyEvent.VK_ENTER);
44-
btnNewButton.addActionListener(e -> {
45-
Main.startGame();
46-
dispose();
47-
});
44+
btnNewButton.addActionListener(e -> { Main.startGame(); dispose(); });
4845
btnNewButton.setFont(new Font("Times New Roman", Font.PLAIN, 15));
4946
contentPanel.add(btnNewButton, BorderLayout.SOUTH);
5047

51-
JLabel lblDeinPunktestand = new JLabel("Dein Punktestand: " + String.valueOf(score));
48+
final JLabel lblDeinPunktestand = new JLabel("Dein Punktestand: " + String.valueOf(score));
5249
lblDeinPunktestand.setFont(new Font("Times New Roman", Font.PLAIN, 25));
5350
contentPanel.add(lblDeinPunktestand, BorderLayout.NORTH);
5451

55-
Image resultImage = Toolkit.getDefaultToolkit()
56-
.getImage(
57-
this.getClass()
58-
.getResource((score < goodOrBadResult) ? "/Try_Again.jpg" : "/1211548-200.png")
59-
);
52+
final Image resultImage = Toolkit.getDefaultToolkit()
53+
.getImage(this.getClass().getResource(score < goodOrBadResult ? "/Try_Again.jpg" : "/1211548-200.png"));
6054
resultImage.flush();
6155
}
6256

0 commit comments

Comments
 (0)