1 7 8 package java.awt; 9 10 import java.awt.geom.Dimension2D ; 11 12 36 public class Dimension extends Dimension2D implements java.io.Serializable { 37 38 45 public int width; 46 47 54 public int height; 55 56 59 private static final long serialVersionUID = 4723952579491349524L; 60 61 64 private static native void initIDs(); 65 66 static { 67 68 Toolkit.loadLibraries(); 69 if (!GraphicsEnvironment.isHeadless()) { 70 initIDs(); 71 } 72 } 73 74 78 public Dimension() { 79 this(0, 0); 80 } 81 82 90 public Dimension(Dimension d) { 91 this(d.width, d.height); 92 } 93 94 101 public Dimension(int width, int height) { 102 this.width = width; 103 this.height = height; 104 } 105 106 110 public double getWidth() { 111 return width; 112 } 113 114 118 public double getHeight() { 119 return height; 120 } 121 122 132 public void setSize(double width, double height) { 133 this.width = (int) Math.ceil(width); 134 this.height = (int) Math.ceil(height); 135 } 136 137 148 public Dimension getSize() { 149 return new Dimension (width, height); 150 } 151 152 161 public void setSize(Dimension d) { 162 setSize(d.width, d.height); 163 } 164 165 177 public void setSize(int width, int height) { 178 this.width = width; 179 this.height = height; 180 } 181 182 185 public boolean equals(Object obj) { 186 if (obj instanceof Dimension ) { 187 Dimension d = (Dimension )obj; 188 return (width == d.width) && (height == d.height); 189 } 190 return false; 191 } 192 193 198 public int hashCode() { 199 int sum = width + height; 200 return sum * (sum + 1)/2 + width; 201 } 202 203 214 public String toString() { 215 return getClass().getName() + "[width=" + width + ",height=" + height + "]"; 216 } 217 } 218 | Popular Tags |