Skip to content

Commit

Permalink
Fixed issue with wrong WindowConstant
Browse files Browse the repository at this point in the history
  • Loading branch information
delvh committed Jul 1, 2020
1 parent a039837 commit b584589
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
26 changes: 11 additions & 15 deletions src/main/dev/lh/Viewport.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Project: <strong>Snake</strong><br>
* File: <strong>Viewport.java</strong><br>
* Created: <strong>01.07.2020</strong><br>
*
*
* @author Kai S. K. Engelbart
* @since Snake 1.2
*/
Expand Down Expand Up @@ -42,24 +42,22 @@ public Viewport(Updateable gameRoot) {

/**
* 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();
Expand All @@ -71,15 +69,13 @@ public void run() {

/**
* 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);
Expand Down
18 changes: 6 additions & 12 deletions src/main/dev/lh/ui/Endscreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit b584589

Please sign in to comment.