public static void main(String[] args) {
		int rows = 0;
		int columns = 0;

		boolean invalidInput = true;
		while (invalidInput) {
			try {
				rows = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the number of rows in the board, or 0 for the default number (20):", "Enter rows", JOptionPane.QUESTION_MESSAGE)); // Prompt the user to enter the width of the board
				invalidInput = false;
			}

			catch (NumberFormatException nfe) {
				JOptionPane.showMessageDialog(null, "Please enter a positive integer.", "Error", JOptionPane.ERROR_MESSAGE);
			}
		}

		invalidInput = true;
		while (invalidInput) {
			try {
				columns = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the columns of rows in the board, or 0 for the default number (20):", "Enter columns", JOptionPane.QUESTION_MESSAGE)); // Prompt the user to enter the height of the board
				invalidInput = false;
			}

			catch (NumberFormatException nfe) {
				JOptionPane.showMessageDialog(null, "Please enter a positive integer.", "Error", JOptionPane.ERROR_MESSAGE);
			}
		}

		rows = rows != 0 ? rows : 20; // If the user entered 0 for the number of rows, set the number of rows to the default (20)
		columns = columns != 0 ? columns : 20; // If the user entered 0 for the number of columns, set the columns of rows to the default (20)

		TurtleGraphics2 tg = new TurtleGraphics2(rows, columns); // Create a new TurtleGraphics object
		JFrame window = new JFrame("Turtle Graphics"); // Create a window with the caption "Turtle Graphics"

		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.add(tg); // Add the TurtleGraphics object to the window
		window.setSize(columns * 20, rows * 20 + 20); // Make the window as big as the board
		window.setVisible(true); // Make the window visible

		String choice = JOptionPane.showInputDialog(null, "Enter:\n"
				+ "\"u\" to put the pen up,\n"
				+ "\"d\" to put the pen down,\n"
				+ "\"l\" to turn left,\n"
				+ "\"r\" to turn right,\n"
				+ "\"e\" to use an eraser,\n"
				+ "\"p\" to draw,\n"
				+ "\"t\" to toggle the pen,\n"
				+ "\"f x\" to move forward x spaces, where x is an integer,\n"
				+ "or \"q\" to quit", "Enter move", JOptionPane.INFORMATION_MESSAGE).toLowerCase(); // Get the user's choice and convert it to all lowercase so that the code is case insensitive


		while (!choice.equals("q")) { // Repeat until the user decides to quit the program
			switch (choice) { // Do different things, depending on the user's input
			case "u": // If the user decided to put the pen up:
				tg.setPenDown(false); // Set the state of the pen to false (up)
				break; // Leave the switch so that the other cases aren't executed

			case "d": // If the user decided to put the pen down:
				tg.setPenDown(true); // Set the state of the pen to true (down)
				break; // Leave the switch so that the other cases aren't executed

			case "l": // If the user decided to turn left:
				tg.turn(true); // Turn the turtle 90deg to the left (counterclockwise)
				break; // Leave the switch so that the other cases aren't executed

			case "r": // If the user decided to turn left:
				tg.turn(false); // Turn the turtle 90deg to the right (clockwise)
				break; // Leave the switch so that the other cases aren't executed

			case "e":
				tg.setEraser(true); // Set the eraser to true
				break; // Leave the switch so that the other cases aren't executed

			case "p":
				tg.setEraser(false); // Set the eraser to false so that the user can draw
				break; // Leave the switch so that the other cases aren't executed

			case "t":
				tg.togglePen(); // Toggle the pen
				break; // Leave the switch so that the other cases aren't executed

			case "q": // If the user decided to quit:
				break; // Do nothing because the end-of-program message and so forth is handled after the while loop

			default: // If none of the cases above are applicable:
				if (choice.length() > 2 && choice.substring(0, 2).equals("f ")) { // Check if the user decided to move forward
					int numForward = Integer.parseInt(choice.substring(2, choice.length())); // Get the number of spaces to move forward

					tg.forward(numForward); // Move forward the number of spaces indicated by the user
				}

				else {JOptionPane.showMessageDialog(null, "I don't understand \"" + choice + "\". Please check your spelling.", "Error", JOptionPane.ERROR_MESSAGE);} // If the user entered an invalid command, let him/her know
			}
			
			tg.repaint(); // Update the window

			choice = JOptionPane.showInputDialog(null,
					"Enter \"l\" to turn left, "
					+ "\"r\" to turn right, "
					+ "\"u\" to lift the pen, "
					+ "\"d\" to lower the pen, "
					+ "\"e\" to use an eraser, "
					+ "\"p\" to draw, "
					+ "\"t\" to toggle the pen, "
					+ "\"f x\" to move forward x spaces, or "
					+ "\"q\" to quit: ", "Choose one", JOptionPane.QUESTION_MESSAGE).toLowerCase(); // Show the one-line version of the menu
		}

		// After the user quits:
		JOptionPane.showMessageDialog(null, "Thank you for using!"); // Print a closing message
		window.dispose();

	}