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

Home
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
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Natural Language Processing
51.Net
52.Parser
53.PDF
54.Portal
55.Profiler
56.Project Management
57.Report
58.RSS RDF
59.Rule Engine
60.Science
61.Scripting
62.Search Engine
63.Security
64.Sevlet Container
65.Source Control
66.Swing Library
67.Template Engine
68.Test Coverage
69.Testing
70.UML
71.Web Crawler
72.Web Framework
73.Web Mail
74.Web Server
75.Web Services
76.Web Services apache cxf 2.2.6
77.Web Services AXIS2
78.Wiki Engine
79.Workflow Engines
80.XML
81.XML UI
Java Source Code / Java Documentation  » 6.0 JDK Core » AWT » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


        /*
         * Copyright 1995-2006 Sun Microsystems, Inc.  All Rights Reserved.
         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
         *
         * This code is free software; you can redistribute it and/or modify it
         * under the terms of the GNU General Public License version 2 only, as
         * published by the Free Software Foundation.  Sun designates this
         * particular file as subject to the "Classpath" exception as provided
         * by Sun in the LICENSE file that accompanied this code.
         *
         * This code is distributed in the hope that it will be useful, but WITHOUT
         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
         * version 2 for more details (a copy is included in the LICENSE file that
         * accompanied this code).
         *
         * You should have received a copy of the GNU General Public License version
         * 2 along with this work; if not, write to the Free Software Foundation,
         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
         *
         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
         * CA 95054 USA or visit www.sun.com if you need additional information or
         * have any questions.
         */

        package java.awt;

        import java.awt.geom.Point2D;

        /**
         * A point representing a location in {@code (x,y)} coordinate space,
         * specified in integer precision.
         *
         * @version 	1.46, 05/05/07
         * @author 	Sami Shaio
         * @since       1.0
         */
        public class Point extends Point2D implements  java.io.Serializable {
            /**
             * The X coordinate of this <code>Point</code>.
             * If no X coordinate is set it will default to 0.
             *
             * @serial
             * @see #getLocation()
             * @see #move(int, int)
             * @since 1.0
             */
            public int x;

            /**
             * The Y coordinate of this <code>Point</code>. 
             * If no Y coordinate is set it will default to 0.
             *
             * @serial
             * @see #getLocation()
             * @see #move(int, int)
             * @since 1.0
             */
            public int y;

            /*
             * JDK 1.1 serialVersionUID 
             */
            private static final long serialVersionUID = -5276940640259749850L;

            /**
             * Constructs and initializes a point at the origin 
             * (0,&nbsp;0) of the coordinate space. 
             * @since       1.1
             */
            public Point() {
                this (0, 0);
            }

            /**
             * Constructs and initializes a point with the same location as
             * the specified <code>Point</code> object.
             * @param       p a point
             * @since       1.1
             */
            public Point(Point p) {
                this (p.x, p.y);
            }

            /**
             * Constructs and initializes a point at the specified 
             * {@code (x,y)} location in the coordinate space. 
             * @param x the X coordinate of the newly constructed <code>Point</code>
             * @param y the Y coordinate of the newly constructed <code>Point</code>
             * @since 1.0
             */
            public Point(int x, int y) {
                this .x = x;
                this .y = y;
            }

            /**
             * {@inheritDoc}
             * @since 1.2
             */
            public double getX() {
                return x;
            }

            /**
             * {@inheritDoc}
             * @since 1.2
             */
            public double getY() {
                return y;
            }

            /**
             * Returns the location of this point.
             * This method is included for completeness, to parallel the
             * <code>getLocation</code> method of <code>Component</code>.
             * @return      a copy of this point, at the same location
             * @see         java.awt.Component#getLocation
             * @see         java.awt.Point#setLocation(java.awt.Point)
             * @see         java.awt.Point#setLocation(int, int)
             * @since       1.1
             */
            public Point getLocation() {
                return new Point(x, y);
            }

            /**
             * Sets the location of the point to the specified location.
             * This method is included for completeness, to parallel the
             * <code>setLocation</code> method of <code>Component</code>.
             * @param       p  a point, the new location for this point
             * @see         java.awt.Component#setLocation(java.awt.Point)
             * @see         java.awt.Point#getLocation
             * @since       1.1
             */
            public void setLocation(Point p) {
                setLocation(p.x, p.y);
            }

            /**
             * Changes the point to have the specified location.
             * <p>
             * This method is included for completeness, to parallel the
             * <code>setLocation</code> method of <code>Component</code>.
             * Its behavior is identical with <code>move(int,&nbsp;int)</code>.
             * @param       x the X coordinate of the new location
             * @param       y the Y coordinate of the new location
             * @see         java.awt.Component#setLocation(int, int)
             * @see         java.awt.Point#getLocation
             * @see         java.awt.Point#move(int, int)
             * @since       1.1
             */
            public void setLocation(int x, int y) {
                move(x, y);
            }

            /**
             * Sets the location of this point to the specified double coordinates.
             * The double values will be rounded to integer values.
             * Any number smaller than <code>Integer.MIN_VALUE</code>
             * will be reset to <code>MIN_VALUE</code>, and any number
             * larger than <code>Integer.MAX_VALUE</code> will be
             * reset to <code>MAX_VALUE</code>.
             *
             * @param x the X coordinate of the new location
             * @param y the Y coordinate of the new location
             * @see #getLocation
             */
            public void setLocation(double x, double y) {
                this .x = (int) Math.floor(x + 0.5);
                this .y = (int) Math.floor(y + 0.5);
            }

            /**
             * Moves this point to the specified location in the 
             * {@code (x,y)} coordinate plane. This method
             * is identical with <code>setLocation(int,&nbsp;int)</code>.
             * @param       x the X coordinate of the new location
             * @param       y the Y coordinate of the new location
             * @see         java.awt.Component#setLocation(int, int)
             */
            public void move(int x, int y) {
                this .x = x;
                this .y = y;
            }

            /**
             * Translates this point, at location {@code (x,y)}, 
             * by {@code dx} along the {@code x} axis and {@code dy} 
             * along the {@code y} axis so that it now represents the point 
             * {@code (x+dx,y+dy)}.
             *
             * @param       dx   the distance to move this point 
             *                            along the X axis
             * @param       dy    the distance to move this point 
             *                            along the Y axis
             */
            public void translate(int dx, int dy) {
                this .x += dx;
                this .y += dy;
            }

            /**
             * Determines whether or not two points are equal. Two instances of
             * <code>Point2D</code> are equal if the values of their 
             * <code>x</code> and <code>y</code> member fields, representing
             * their position in the coordinate space, are the same.
             * @param obj an object to be compared with this <code>Point2D</code>
             * @return <code>true</code> if the object to be compared is
             *         an instance of <code>Point2D</code> and has
             *         the same values; <code>false</code> otherwise.
             */
            public boolean equals(Object obj) {
                if (obj instanceof  Point) {
                    Point pt = (Point) obj;
                    return (x == pt.x) && (y == pt.y);
                }
                return super .equals(obj);
            }

            /**
             * Returns a string representation of this point and its location 
             * in the {@code (x,y)} coordinate space. This method is 
             * intended to be used only for debugging purposes, and the content 
             * and format of the returned string may vary between implementations. 
             * The returned string may be empty but may not be <code>null</code>.
             * 
             * @return  a string representation of this point
             */
            public String toString() {
                return getClass().getName() + "[x=" + x + ",y=" + y + "]";
            }
        }
w_w__w__._jav__a_2___s___.co_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.