Fix missing ImageIcon for PlayButton and repeated EndScreen Spawning #3
@@ -40,14 +40,6 @@ public class Endscreen extends JDialog {
 | 
			
		||||
			contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
 | 
			
		||||
			contentPanel.setLayout(new BorderLayout(0, 0));
 | 
			
		||||
			getContentPane().add(contentPanel, BorderLayout.CENTER);
 | 
			
		||||
			addWindowListener(new java.awt.event.WindowAdapter() {
 | 
			
		||||
 | 
			
		||||
				@Override
 | 
			
		||||
				public void windowClosing(java.awt.event.WindowEvent windowEvent) {
 | 
			
		||||
					Thread.getAllStackTraces().forEach((thread, stackTraceElement) -> thread.interrupt());
 | 
			
		||||
					System.exit(0);
 | 
			
		||||
				}
 | 
			
		||||
			});
 | 
			
		||||
 | 
			
		||||
			JButton btnNewButton = new JButton("Play again");
 | 
			
		||||
			btnNewButton.setMnemonic(KeyEvent.VK_ENTER);
 | 
			
		||||
 
 | 
			
		||||
@@ -25,6 +25,7 @@ public class GameWindow extends JFrame {
 | 
			
		||||
	private static final long	serialVersionUID	= 1L;
 | 
			
		||||
	private Snake				s					= new Snake(7);
 | 
			
		||||
	private FoodFactory			foodFactory			= FoodFactory.getInstance();
 | 
			
		||||
	private Timer timer;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param title the title of the frame
 | 
			
		||||
@@ -84,7 +85,8 @@ public class GameWindow extends JFrame {
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		Timer timer = new Timer(50,
 | 
			
		||||
		timer = new Timer(
 | 
			
		||||
			50,
 | 
			
		||||
				evt -> { s.nextFrame(); if (System.currentTimeMillis() >= foodFactory.getTimeOfNextFood()) newFood(); repaint(); });
 | 
			
		||||
		timer.start();
 | 
			
		||||
 | 
			
		||||
@@ -107,5 +109,8 @@ public class GameWindow extends JFrame {
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Snake 1.1
 | 
			
		||||
	 */
 | 
			
		||||
	public void close() { dispose(); }
 | 
			
		||||
	public void close() {
 | 
			
		||||
		timer.stop();
 | 
			
		||||
		dispose();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user