public void saveGame() {
		Image resizedImage = background.getImage().getScaledInstance(400, 300,
				Image.SCALE_SMOOTH);
		background = new ImageIcon(resizedImage);

		JPanel mainPanel = new JPanel() {
			// Displays the background image on the panel.
			@Override
			public void paintComponent(Graphics g) {
				g.drawImage(background.getImage(), 0, 0, null);
			}
		};

		final JDialog d = new JDialog(currentFrame, "Save Game", true);
		d.setSize(400, 300);
		d.setLayout(new BorderLayout());

		String[] loadNames = Data.getLoadFiles();

		final DefaultListModel<String> model = new DefaultListModel<String>(); // Add
		// saved
		// game
		// names
		// to
		// this
		// model.

		// This loop populates the list of saved games to be displayed in the
		// scroll pane.
		for (String name : loadNames) {
			model.addElement(name);
		}
		final JList<String> list = new JList<String>(model);
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Makes
																	// sure
																	// that
																	// the
																	// user
																	// can
																	// only
																	// select
																	// one
																	// game
																	// to
																	// load.
		final JScrollPane scrollPane = new JScrollPane(list);

		JPanel savePanel = new JPanel();
		savePanel.setLayout(new BorderLayout());

		JPanel namePanel = new JPanel();
		namePanel.setLayout(new FlowLayout());
		namePanel.add(new JLabel("Name: "));
		final JTextField nameField = new JTextField();
		nameField.setPreferredSize(new Dimension(110, 20));
		namePanel.add(nameField);

		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new FlowLayout());
		JButton cancelButton = new JButton("Cancel");
		cancelButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				d.dispose();
			}
		});
		JButton okButton = new JButton("OK");
		okButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				String name = nameField.getText();

				// The patterns are used to check whether there are any spaces
				// or special characters in the name that the user types in.
				Pattern alphaNumeric = Pattern.compile("^[a-zA-Z0-9]*$");
				java.util.regex.Matcher match1 = alphaNumeric.matcher(name);
				Pattern spaces = Pattern.compile("\\s");
				java.util.regex.Matcher match2 = spaces.matcher(name);

				// If there are no spaces or special characters then it goes
				// ahead to save the game with the specified file name.
				if (match1.matches() && !match2.find()) {
					try {
						Data.save(name);
					} catch (UnexpectedException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					d.dispose();

					// If the quit button is pressed then the game closes and
					// the panel is switched to the main menu.
					if (mode.equals("Quit")) {
						moveType = "arrows";
						currentFrame.getContentPane().removeAll();
						currentFrame.getContentPane().validate();
						currentFrame.getContentPane().repaint();

						currentFrame.getContentPane().add(oldPanel,
								BorderLayout.CENTER);

						currentFrame.getContentPane().validate();
						currentFrame.getContentPane().repaint();
					}
				} else {
					JOptionPane.showMessageDialog(GamePanel.this,
							"Name must be alphanumeric with no spaces!",
							"Warning", JOptionPane.WARNING_MESSAGE);
				}
			}
		});
		JButton deleteButton = new JButton("Delete");
		deleteButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				String n = list.getSelectedValue();
				Data.deleteFile(n);

				String[] modifiedList = Data.getLoadFiles();

				model.removeAllElements();

				for (String name : modifiedList) {
					model.addElement(name);
				}

				list.setModel(model);
				scrollPane.revalidate();
				scrollPane.repaint();

			}
		});

		// Displays the selected game in the textbox.
		list.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 1) {
					String selectedItem = (String) list.getSelectedValue();
					nameField.setText(selectedItem);
				}
			}
		});

		buttonPanel.add(okButton);
		buttonPanel.add(cancelButton);
		buttonPanel.add(deleteButton);

		// To make sure that the background image can be displayed.
		scrollPane.setOpaque(false);
		namePanel.setOpaque(false);
		buttonPanel.setOpaque(false);
		savePanel.setOpaque(false);

		savePanel.add(namePanel, BorderLayout.CENTER);
		savePanel.add(buttonPanel, BorderLayout.SOUTH);

		mainPanel.setLayout(new BorderLayout());
		mainPanel.add(scrollPane, BorderLayout.CENTER);
		mainPanel.add(savePanel, BorderLayout.SOUTH);
		d.add(mainPanel, BorderLayout.CENTER);

		d.setLocationRelativeTo(null);
		d.setVisible(true);
	}