legacyline.java

来自「程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件」· Java 代码 · 共 51 行

JAVA
51
字号
package examples.collections;

import java.util.Vector;
import java.util.Enumeration;
import java.io.PrintStream;
import java.awt.Point;

/** A class to demonstrate the use of the Vector and
  * Enumeration classes in the java.util package
  */
public class LegacyLine {

   private Vector points = new Vector();

   /** Set the starting point for a line
     * @param p the starting point
     */
   public void setStart( Point p ) {
      points.removeAllElements();
      points.addElement( p );
   }

   /** Set the next point in a line
     * @param p the next point
     */
   public void addPoint( Point p ) {
      points.addElement( p );
   }

   /** Print all the points in a line
     * @param ps the stream where the points
     *           will be printed
     */
   public void listPoints( PrintStream ps ) {
      Enumeration e = points.elements();
      while ( e.hasMoreElements() ) {
         ps.println( e.nextElement() );
      }
   }

   /** Test method for the class
     * @param args not used
     */
   public static void main( String[] args ) {
      LegacyLine x = new LegacyLine();
      x.setStart( new Point( 4, 11 ) );
      x.addPoint( new Point( -6, 1 ) );
      x.addPoint( new Point( 2, 3 ) );
      x.listPoints( System.out );
   }
}

⌨️ 快捷键说明

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