private void setListeners() {
		/*
		 * The action listener for remove carriage button
		 */
		btnRemove.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				try {
					theTrain.removeCarriage();
				} catch (TrainException e1) {
					e1.printStackTrace();
				}
				reconfigure();
			}
		});

		/*
		 * The action listener for add freight car button
		 */
		btnFreightcar.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				FreightCarChoice freiChoice = new FreightCarChoice(
						MainPage.this.frame, theTrain);
				freiChoice.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
				freiChoice.setVisible(true);
				reconfigure();
			}
		});

		/*
		 * The action listener for add passenger car button
		 */
		btnPassengercar.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				PassengerCarChoice passChoice = new PassengerCarChoice(
						MainPage.this.frame, theTrain);
				passChoice.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
				passChoice.setVisible(true);
				reconfigure();
			}
		});

		/*
		 * The action listener for add locomotive button
		 */
		btnLocomotive.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				LocomotiveChoice locoChoice = new LocomotiveChoice(
						MainPage.this.frame, theTrain);
				locoChoice.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
				locoChoice.setVisible(true);
				reconfigure();
			}
		});
		/*
		 * The action listener for reset button
		 */
		btnReset.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				passengersOnBoard = 0;
				totalSeats = 0;
				power = 0;
				totalWeight = 0;
				passengersRefused = 0;
				theTrain = new DepartingTrain();
				reconfigure();

			}
		});
		/*
		 * The action listener for board button
		 */
		btnBoard.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				int toBoard = Integer.parseInt((spinnerToBoard.getValue()
						.toString()));
				RollingStock r = theTrain.firstCarriage();
				int remaining = (totalSeats - passengersOnBoard); 			// now, remaining == seats available
				remaining = remaining > toBoard ? toBoard : remaining; 		// now, remaining == number to board
				passengersRefused += toBoard - remaining;
				passengersOnBoard += remaining;

				r = theTrain.nextCarriage();
				while (r != null
						&& r.getClass().getName() == "asgn2RollingStock.PassengerCar"
						&& remaining > 0) {
					if (remaining > ((PassengerCar) r).numberOfSeats()
							- ((PassengerCar) r).numberOnBoard()) {
						try {
							int tmpBoarding = ((PassengerCar) r)
									.numberOfSeats()
									- ((PassengerCar) r).numberOnBoard();
							((PassengerCar) r).board(tmpBoarding);
							remaining -= tmpBoarding;
						} catch (TrainException e1) {
							e1.printStackTrace();
						}
					} else {
						try {
							((PassengerCar) r).board(remaining);
							remaining = 0;
						} catch (TrainException e1) {
							e1.printStackTrace();
						}
					}
					r = theTrain.nextCarriage();
				}
				reconfigure();
			}
		});

	}