Source Code Cross Referenced for Point.java in  » 6.0-JDK-Core » AWT » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1995-2006 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package java.awt;
027:
028:        import java.awt.geom.Point2D;
029:
030:        /**
031:         * A point representing a location in {@code (x,y)} coordinate space,
032:         * specified in integer precision.
033:         *
034:         * @version 	1.46, 05/05/07
035:         * @author 	Sami Shaio
036:         * @since       1.0
037:         */
038:        public class Point extends Point2D implements  java.io.Serializable {
039:            /**
040:             * The X coordinate of this <code>Point</code>.
041:             * If no X coordinate is set it will default to 0.
042:             *
043:             * @serial
044:             * @see #getLocation()
045:             * @see #move(int, int)
046:             * @since 1.0
047:             */
048:            public int x;
049:
050:            /**
051:             * The Y coordinate of this <code>Point</code>. 
052:             * If no Y coordinate is set it will default to 0.
053:             *
054:             * @serial
055:             * @see #getLocation()
056:             * @see #move(int, int)
057:             * @since 1.0
058:             */
059:            public int y;
060:
061:            /*
062:             * JDK 1.1 serialVersionUID 
063:             */
064:            private static final long serialVersionUID = -5276940640259749850L;
065:
066:            /**
067:             * Constructs and initializes a point at the origin 
068:             * (0,&nbsp;0) of the coordinate space. 
069:             * @since       1.1
070:             */
071:            public Point() {
072:                this (0, 0);
073:            }
074:
075:            /**
076:             * Constructs and initializes a point with the same location as
077:             * the specified <code>Point</code> object.
078:             * @param       p a point
079:             * @since       1.1
080:             */
081:            public Point(Point p) {
082:                this (p.x, p.y);
083:            }
084:
085:            /**
086:             * Constructs and initializes a point at the specified 
087:             * {@code (x,y)} location in the coordinate space. 
088:             * @param x the X coordinate of the newly constructed <code>Point</code>
089:             * @param y the Y coordinate of the newly constructed <code>Point</code>
090:             * @since 1.0
091:             */
092:            public Point(int x, int y) {
093:                this .x = x;
094:                this .y = y;
095:            }
096:
097:            /**
098:             * {@inheritDoc}
099:             * @since 1.2
100:             */
101:            public double getX() {
102:                return x;
103:            }
104:
105:            /**
106:             * {@inheritDoc}
107:             * @since 1.2
108:             */
109:            public double getY() {
110:                return y;
111:            }
112:
113:            /**
114:             * Returns the location of this point.
115:             * This method is included for completeness, to parallel the
116:             * <code>getLocation</code> method of <code>Component</code>.
117:             * @return      a copy of this point, at the same location
118:             * @see         java.awt.Component#getLocation
119:             * @see         java.awt.Point#setLocation(java.awt.Point)
120:             * @see         java.awt.Point#setLocation(int, int)
121:             * @since       1.1
122:             */
123:            public Point getLocation() {
124:                return new Point(x, y);
125:            }
126:
127:            /**
128:             * Sets the location of the point to the specified location.
129:             * This method is included for completeness, to parallel the
130:             * <code>setLocation</code> method of <code>Component</code>.
131:             * @param       p  a point, the new location for this point
132:             * @see         java.awt.Component#setLocation(java.awt.Point)
133:             * @see         java.awt.Point#getLocation
134:             * @since       1.1
135:             */
136:            public void setLocation(Point p) {
137:                setLocation(p.x, p.y);
138:            }
139:
140:            /**
141:             * Changes the point to have the specified location.
142:             * <p>
143:             * This method is included for completeness, to parallel the
144:             * <code>setLocation</code> method of <code>Component</code>.
145:             * Its behavior is identical with <code>move(int,&nbsp;int)</code>.
146:             * @param       x the X coordinate of the new location
147:             * @param       y the Y coordinate of the new location
148:             * @see         java.awt.Component#setLocation(int, int)
149:             * @see         java.awt.Point#getLocation
150:             * @see         java.awt.Point#move(int, int)
151:             * @since       1.1
152:             */
153:            public void setLocation(int x, int y) {
154:                move(x, y);
155:            }
156:
157:            /**
158:             * Sets the location of this point to the specified double coordinates.
159:             * The double values will be rounded to integer values.
160:             * Any number smaller than <code>Integer.MIN_VALUE</code>
161:             * will be reset to <code>MIN_VALUE</code>, and any number
162:             * larger than <code>Integer.MAX_VALUE</code> will be
163:             * reset to <code>MAX_VALUE</code>.
164:             *
165:             * @param x the X coordinate of the new location
166:             * @param y the Y coordinate of the new location
167:             * @see #getLocation
168:             */
169:            public void setLocation(double x, double y) {
170:                this .x = (int) Math.floor(x + 0.5);
171:                this .y = (int) Math.floor(y + 0.5);
172:            }
173:
174:            /**
175:             * Moves this point to the specified location in the 
176:             * {@code (x,y)} coordinate plane. This method
177:             * is identical with <code>setLocation(int,&nbsp;int)</code>.
178:             * @param       x the X coordinate of the new location
179:             * @param       y the Y coordinate of the new location
180:             * @see         java.awt.Component#setLocation(int, int)
181:             */
182:            public void move(int x, int y) {
183:                this .x = x;
184:                this .y = y;
185:            }
186:
187:            /**
188:             * Translates this point, at location {@code (x,y)}, 
189:             * by {@code dx} along the {@code x} axis and {@code dy} 
190:             * along the {@code y} axis so that it now represents the point 
191:             * {@code (x+dx,y+dy)}.
192:             *
193:             * @param       dx   the distance to move this point 
194:             *                            along the X axis
195:             * @param       dy    the distance to move this point 
196:             *                            along the Y axis
197:             */
198:            public void translate(int dx, int dy) {
199:                this .x += dx;
200:                this .y += dy;
201:            }
202:
203:            /**
204:             * Determines whether or not two points are equal. Two instances of
205:             * <code>Point2D</code> are equal if the values of their 
206:             * <code>x</code> and <code>y</code> member fields, representing
207:             * their position in the coordinate space, are the same.
208:             * @param obj an object to be compared with this <code>Point2D</code>
209:             * @return <code>true</code> if the object to be compared is
210:             *         an instance of <code>Point2D</code> and has
211:             *         the same values; <code>false</code> otherwise.
212:             */
213:            public boolean equals(Object obj) {
214:                if (obj instanceof  Point) {
215:                    Point pt = (Point) obj;
216:                    return (x == pt.x) && (y == pt.y);
217:                }
218:                return super .equals(obj);
219:            }
220:
221:            /**
222:             * Returns a string representation of this point and its location 
223:             * in the {@code (x,y)} coordinate space. This method is 
224:             * intended to be used only for debugging purposes, and the content 
225:             * and format of the returned string may vary between implementations. 
226:             * The returned string may be empty but may not be <code>null</code>.
227:             * 
228:             * @return  a string representation of this point
229:             */
230:            public String toString() {
231:                return getClass().getName() + "[x=" + x + ",y=" + y + "]";
232:            }
233:        }
w__w__w__._j___a___va2s_._c_o__m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.