📄 line.java
字号:
package examples.collections;
import java.util.List;
import java.util.ArrayList;
import java.util.ListIterator;
import java.io.PrintStream;
import java.awt.Point;
/** A class to demonstrate the use of the ArrayList
* and Iterator classes in the java.util package
*/
public class Line {
private List points = new ArrayList();
/** Set the starting point for a line
* @param p the starting point
*/
public void setStart( Point p ) {
points.clear();
points.add( p );
}
/** Set the next point in a line
* @param p the next point
*/
public void addPoint( Point p ) {
points.add( p );
}
/** Print all the points in a line
* @param ps the stream where the points
* will be printed
*/
public void listPoints( PrintStream ps ) {
ListIterator li = points.listIterator();
while ( li.hasNext() ) {
ps.println( li.next() );
}
}
/** Test method for the class
* @param args not used
*/
public static void main( String[] args ) {
Line x = new Line();
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -