⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pointiterator.java

📁 利用BlueJ开发的一个类似小时候完的吃豆豆的小游戏
💻 JAVA
字号:
package cs101.awt.geom;import java.awt.Shape;import java.awt.geom.Point2D;import java.awt.geom.PathIterator;/** * This class provides a simple interface for listing all the knot * points in an <code>java.awt.Shape</code>. * * @author Patrick G. Heck gus.heck@olin.edu * @version $Id: PointIterator.java,v 1.7 2003/03/06 21:58:16 gus Exp $ */public class PointIterator {        //    GeneralPath ourPath;    PathIterator iter;    Point2D.Float pathStart;    float[] data = new float[6];        /**     * Creates a <code>PointIterator</code> for the specified <code>Shape</code>.     *     * @param s the <code>Shape</code> to iterate over.     */    public PointIterator(Shape s) {        iter = s.getPathIterator(null);    }        /**     * Test to see if the entire shape has been processed.     *     * @return <code>true</code> if all points in the shape have been returned.     *         <code>false</code> otherwise.     */        public boolean hasNext() {        return !iter.isDone();    }        /**     * Test to see if the supplied point is the same object as the current     * start point for the current path. If this test fails after it has     * succeeded then the itterator can be assumed to have begun a new portion     * of a discontinuous <code>GeneralPath</code>, or similar shape.     *     * @param pt The point to test     */         public boolean isStart(Point2D.Float pt) {        return pt == pathStart;    }        /**     * Return the next point in the shape. When a path in the shape is closed,     * The object returned is the same object that was returned for the last     * moveTo such that (return value of moveTo) == (return value of close).     * Note that this is only useful for simple shapes that contain only one     * path. There is no means provided in <code>PathIterator</code> to     * distinguish points returned from a moveTo segments beyond the     * first segment (which is guaranteed by Sun to be a moveTo).     *     * @return The next point in the shape.     */    public Point2D.Float nextPoint() {        int segType = iter.currentSegment(data);        iter.next();        switch (segType) {            case PathIterator.SEG_MOVETO:                pathStart = new Point2D.Float(data[0],data[1]);                return pathStart;                            case PathIterator.SEG_CLOSE:                return pathStart;                            case PathIterator.SEG_LINETO:                return new Point2D.Float(data[0],data[1]);                            case PathIterator.SEG_QUADTO:                return new Point2D.Float(data[2],data[3]);                            case PathIterator.SEG_CUBICTO:                return new Point2D.Float(data[4],data[5]);                            default:                throw new Error("This only hapens if Sun changes PathIterator");                        }            }}/* * $Log: PointIterator.java,v $ * Revision 1.7  2003/03/06 21:58:16  gus * even better doc * * Revision 1.6  2003/03/06 21:56:54  gus * better doc * * Revision 1.5  2003/03/06 21:54:02  gus * add a method to test for equivalance with the start of the current path. * * Revision 1.4  2003/03/06 18:55:56  gus * we need to advance the pathIterator despite what the nutshell book claims * * Revision 1.3  2003/03/04 16:04:45  gus * Javadoc improvements * * Revision 1.2  2003/03/04 15:32:20  gus * adding log comment * */

⌨️ 快捷键说明

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