river.java

来自「A part public bus simulation system, mai」· Java 代码 · 共 128 行

JAVA
128
字号
//Coded by Chen Chuan and Dai Xiaoming

//GUI creates a river object using this class and then passes it to MapCanvas
//Only MapCanvas can do the checking and setting to the map matrix 
package tools;
import java.awt.Point;

public class River extends AreaTools{
	private Point start;        //start point of the river
	private Point end;          //end point of the river
	private boolean direction;  //0 for hori 1 for vertical
	private int size;           //the length of the river
	
	public River(Point s, Point e, String name){   //constructor, GUI calls this to create a river
	    super(s,e);
          setID(10);                          //10 is the ID for river
          super.setName(name);                //set name in the super class
      
	    start=new Point(s); 
	    end=new Point(e);
	    double x1,x2;
	    Point temp;                         //for exchange points
	    x1=start.getX();                    //x value of start point
	    x2=end.getX();                      //x value of end point
	    
	    if (x1==x2) {             //the river is vertical
	    	direction=true;
	    	if (start.getY()>end.getY())  //make sure that the size is positive 
	    		size=(int)(start.getY()-end.getY()+1);
	    	else 
	    		size=(int)(end.getY()-start.getY()+1);             
	    	}
	    else {                    //the river is horizontal
	    	direction=false;
	    	if (x1>x2) size=(int)((x1-x2)+1);
	    	else size=(int)((x2-x1)+1);
	    	}
	    	
          if (x1>x2)                    //make sure that start.x<=end.x
     		{temp=start;start=end;end=temp;}

          else if (start.getY()>end.getY()) //make sure the start.y<=end.y
     		{temp=start;start=end;end=temp;}
	}
      
	public int getSize(){       //returns the length of the river
		return size;
	}
	
	public Point getStart(){    //returns the start point of the river
		return start;
	}
	
	public Point getEnd(){      //returns the end point of the river
		return end;
	}
	
	public boolean getDirect(){ //returns the direction of the river
		return direction;
	}
      //GetName, SetName inherited
}

/*//delete the function set from river class

package tools;
import java.awt.Point;

public class River extends AreaTools{
	private Point start;
	private Point end;
	private boolean direction;  //0 for hori 1 for vertical
	private int size;
	
	public River(Point s, Point e, String name){   //already checked in canvas
	    super(s,e);
        setID(10);
        super.setName(name);
        
	    start=new Point(s);
	    end=new Point(e);
	    double x1,x2;
	    Point temp;
	    x1=start.getX();
	    x2=end.getX();
	    
	    if (x1==x2) {
	    	direction=true;
	    	if (x1>x2) size=(int)((x1-x2)+1);
	    	else size=(int)((x2-x1)+1);
	    	}
	    else {
	    	direction=false;
	    	if (start.getY()>end.getY()) 
	    		size=(int)(start.getY()-end.getY()+1);
	    	else 
	    		size=(int)(end.getY()-start.getY()+1);
	    	}
	    	
        if (x1>x2) 
       		//edited by SYS
       		//{temp=start;start=end;end=start;}
       		{temp=start;start=end;end=temp;}
       		//end edited by SYS

        else if (start.getY()>end.getY())
       		//edited by SYS
       		//{temp=start;start=end;end=start;}
       		{temp=start;start=end;end=temp;}
       		//end edited by SYS
	}
        
	public int getSize(){
		return size;
	}
	
	public Point getStart(){
		return start;
	}
	
	public Point getEnd(){
		return end;
	}
	
	public boolean getDirect(){
		return direction;
	}
}*/

⌨️ 快捷键说明

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