public void paint(Graphics g) { super.paint(g); if (screen.equalsIgnoreCase("title")) { MyPanel.score = 0; hs = new Highscore(); c.removeAll(); c.add(ts); panel = null; ts.revalidate(); } else if (screen.equalsIgnoreCase("instructions")) { c.removeAll(); c.add(instructions); instructions.revalidate(); } else if (screen.equalsIgnoreCase("mode")) { c.removeAll(); c.add(mode); mode.revalidate(); } else if (screen.equalsIgnoreCase("difficulty")) { c.removeAll(); c.add(dif); dif.revalidate(); } else if (screen.equalsIgnoreCase("highscore")) { if (hs.returnCount() == 0) { c.removeAll(); c.add(hs); c.validate(); } } else if (screen.equalsIgnoreCase("gameover")) { if (!once) { c.removeAll(); c.add(gg); once = true; c.validate(); } } else { if (once) { c.removeAll(); panel = new MyPanel(THA.WIDTH, THA.HEIGHT, ai, diff); c.setLayout(new BorderLayout()); c.add(panel.returnNs(), BorderLayout.WEST); c.add(panel, BorderLayout.CENTER); c.add(btns, BorderLayout.SOUTH); c.add(panel.returnAmmo(), BorderLayout.EAST); c.validate(); once = false; } } repaint(); }
public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.equalsIgnoreCase("Exit")) { // Exits the game System.exit(0); // MyFrame.screen = "title"; // MyFrame.once=true; } else if (command.equalsIgnoreCase("Submit")) { String user = name.getText(); // name of user if (user.equalsIgnoreCase("") || user == null) { user = "******"; } try { Highscore.write(MyPanel.score, user); } catch (IOException e1) { e1.printStackTrace(); } System.exit(0); // MyFrame.screen = "title"; // MyFrame.once=true; } }