jfdimension.java
来自「用Java开发的、实现类似Visio功能的应用程序源码」· Java 代码 · 共 177 行
JAVA
177 行
/**
* $Id:JFDimension.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved. *
*/
package com.jfimagine.jfgraph.geom;
/**
* JFDimension class. A class used to represent a dimension in the plane with double values.
*
* @author CookieMaker
*
* @version $Revision: 1.00 $
*/
public class JFDimension implements Cloneable{
/**
* height of this dimension.
*/
private double m_height =0;
/**
* width of this dimension.
*/
private double m_width =0;
/**
* Get height of this dimension.
*
* @return The height.
*
*/
public double getHeight(){
return m_height;
}
/**
* Set height of this dimension.
*
* @param val A new height.
*
*/
public void setHeight(double val){
m_height =val;
}
/**
* Get width of this dimension.
*
* @return The width.
*
*/
public double getWidth(){
return m_width;
}
/**
* Set width of this dimension.
*
* @param val A new width.
*
*/
public void setWidth(double val){
m_width =val;
}
/**
* Constructor for JFDimension.
* Default to 0 for height and width.
*
*/
public JFDimension(){
m_width =0;
m_height =0;
}
/**
* Constructor for JFDimension.
*
* @param width Width of this dimension.
*
* @param height Height of this dimension.
*
*/
public JFDimension(double width, double height){
m_width =width;
m_height =height;
}
/**
* Constructor for JFDimension.
*
* @param pnt A JFDimension.
*
*/
public JFDimension(JFDimension pnt){
if (pnt!=null){
m_width =pnt.getWidth();
m_height =pnt.getHeight();
}
}
/**
* Convert this object to String
*
* @return An string represents the content of the object
*
*/
public String toString(){
StringBuffer buf =new StringBuffer();
buf.append(";width="); buf.append(m_width);
buf.append(";height="); buf.append(m_height);
return buf.toString();
}
/**
* Creates a new object of the same class and with the same contents as this object.
*
* @return A clone of this instance.
*
*/
public Object clone() throws CloneNotSupportedException{
try{
return new JFDimension(this);
}catch(Exception e){
throw new CloneNotSupportedException(e.getMessage());
}
}
/**
* Returns the hashcode for this Object.
*
* @return hash code for this Point2D.
*
*/
public int hashCode(){
long x =Double.doubleToLongBits(m_height);
long y =Double.doubleToLongBits(m_width);
return (int)(x ^ (x >>> 32)) ^ (int)(y ^ (y >>> 32));
}
/**
* Determines whether or not two objects are equal.
*
* @param obj an object to be compared with this object
*
* @return true if the object to be compared is an instance of Port and has the same values; false otherwise.
*
*/
public boolean equals(Object obj){
if (obj == this)
return true;
if (!(obj instanceof JFDimension))
return false;
JFDimension pnt =(JFDimension)obj;
return (m_width==pnt.getWidth()) && (m_height==pnt.getHeight());
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?