passenger.java

来自「现在在国外大学里最流行的java学习软件,同时还有大量的example,在名为p」· Java 代码 · 共 79 行

JAVA
79
字号
import java.awt.Image;import javax.swing.ImageIcon;/** * Model a passenger wishing to get from one * location to another. *  * @author David J. Barnes and Michael Kolling * @version 2006.03.30 */public class Passenger implements DrawableItem{    private Location pickup;    private Location destination;    private Image image;    /**     * Constructor for objects of class Passenger     * @param pickup The pickup location, must not be null.     * @param destination The destination location, must not be null.     * @throws NullPointerException If either location is null.     */    public Passenger(Location pickup, Location destination)    {        if(pickup == null) {            throw new NullPointerException("Pickup location");        }        if(destination == null) {            throw new NullPointerException("Destination location");        }        this.pickup = pickup;        this.destination = destination;        // Load the image used to represent a person.        image = new ImageIcon(getClass().getResource(                              "images/person.jpg")).getImage();    }        /**     * @return A string representation of this person.     */    public String toString()    {        return "Passenger travelling from " +               pickup + " to " + destination;    }    /**     * @return The image to be displayed on a GUI.     */    public Image getImage()    {        return image;    }        /**     * @return The passenger's pickup location.     */    public Location getLocation()    {        return pickup;    }    /**     * @return The pickup location.     */    public Location getPickupLocation()    {        return pickup;    }        /**     * @return The destination location.     */    public Location getDestination()    {        return destination;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?