From b5845894594591a95fb6f8ff6f0e21ca0539bd00 Mon Sep 17 00:00:00 2001 From: delvh Date: Wed, 1 Jul 2020 20:31:55 +0200 Subject: [PATCH] Fixed issue with wrong WindowConstant --- src/main/dev/lh/Viewport.java | 26 +++++++++++--------------- src/main/dev/lh/ui/Endscreen.java | 18 ++++++------------ 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/main/dev/lh/Viewport.java b/src/main/dev/lh/Viewport.java index 874c436..7e4121d 100644 --- a/src/main/dev/lh/Viewport.java +++ b/src/main/dev/lh/Viewport.java @@ -12,7 +12,7 @@ import java.util.TimerTask; * Project: Snake
* File: Viewport.java
* Created: 01.07.2020
- * + * * @author Kai S. K. Engelbart * @since Snake 1.2 */ @@ -42,24 +42,22 @@ public class Viewport extends Canvas { /** * Starts the render task. - * + * * @since Snake 1.2 */ public void start() { - if (renderTask != null) - renderTask.cancel(); - else - createBufferStrategy(2); + if (renderTask != null) renderTask.cancel(); + else createBufferStrategy(2); renderTask = new TimerTask() { - private long lastTime = System.currentTimeMillis(); + // private long lastTime = System.currentTimeMillis(); @Override public void run() { - long time = System.currentTimeMillis(); - double dt = (time - lastTime) * 1E-3; - lastTime = time; + // final long time = System.currentTimeMillis(); + // final double dt = (time - lastTime) * 1E-3; + // lastTime = time; // TODO: Delta time adjustment gameRoot.tick(); render(); @@ -71,15 +69,13 @@ public class Viewport extends Canvas { /** * Stops the render task. - * + * * @since Snake 1.2 */ - public void stop() { - renderTask.cancel(); - } + public void stop() { renderTask.cancel(); } private void render() { - Graphics2D g = (Graphics2D) getBufferStrategy().getDrawGraphics(); + final Graphics2D g = (Graphics2D) getBufferStrategy().getDrawGraphics(); // Clear the screen g.setColor(Color.BLACK); diff --git a/src/main/dev/lh/ui/Endscreen.java b/src/main/dev/lh/ui/Endscreen.java index 56fdc07..6ea362a 100644 --- a/src/main/dev/lh/ui/Endscreen.java +++ b/src/main/dev/lh/ui/Endscreen.java @@ -32,31 +32,25 @@ public class Endscreen extends JDialog { public Endscreen(int score) { this.score = score; setTitle("Endscreen"); - setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setBounds(100, 100, 700, 700); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPanel.setLayout(new BorderLayout(0, 0)); getContentPane().add(contentPanel, BorderLayout.CENTER); - JButton btnNewButton = new JButton("Play again"); + final JButton btnNewButton = new JButton("Play again"); btnNewButton.setMnemonic(KeyEvent.VK_ENTER); - btnNewButton.addActionListener(e -> { - Main.startGame(); - dispose(); - }); + btnNewButton.addActionListener(e -> { Main.startGame(); dispose(); }); btnNewButton.setFont(new Font("Times New Roman", Font.PLAIN, 15)); contentPanel.add(btnNewButton, BorderLayout.SOUTH); - JLabel lblDeinPunktestand = new JLabel("Dein Punktestand: " + String.valueOf(score)); + final JLabel lblDeinPunktestand = new JLabel("Dein Punktestand: " + String.valueOf(score)); lblDeinPunktestand.setFont(new Font("Times New Roman", Font.PLAIN, 25)); contentPanel.add(lblDeinPunktestand, BorderLayout.NORTH); - Image resultImage = Toolkit.getDefaultToolkit() - .getImage( - this.getClass() - .getResource((score < goodOrBadResult) ? "/Try_Again.jpg" : "/1211548-200.png") - ); + final Image resultImage = Toolkit.getDefaultToolkit() + .getImage(this.getClass().getResource(score < goodOrBadResult ? "/Try_Again.jpg" : "/1211548-200.png")); resultImage.flush(); }