Class Ppl

java.lang.Object
  extended by Ppl

public class Ppl
extends java.lang.Object


Constructor Summary
Ppl()
           
 
Method Summary
static char[] charFromFile(java.lang.String fileName)
          reads the whole content of a file and returns it as a char array
static char[] charFromFile(java.lang.String fileName, java.lang.String charsetName)
          reads the whole content of a file and returns it as a char array
static void clear()
          Removes all shapes from the window.
static int drawCircle(double cx, double cy, double r)
           
static int drawLine(double x1, double y1, double x2, double y2)
           
static int drawLine(double x1, double y1, double x2, double y2, java.awt.Color color)
           
static boolean endOfInput()
          Test for availability of more input.
static int erase(java.awt.Shape shape)
          Adds a white shape to the window.
static int eraseCircle(double cx, double cy, double r)
           
static void failWith(java.lang.String message)
          Throws an new exception with the given message
static boolean hasNextDouble()
          Tells whether a double is available on input
static boolean hasNextInt()
          Tells whether an int is available on input
static void initDrawing(java.lang.String s, int x, int y, int w, int h)
          Opens a drawing window.
static int paint(java.awt.Shape shape, java.awt.Color fg, java.awt.Color bg)
          Adds a shape to the window.
static int paintCircle(double cx, double cy, double r)
           
static int paintCircle(double cx, double cy, double r, java.awt.Color fg, java.awt.Color bg)
           
static char readChar()
          Reads a single character from the input.
static double readDouble()
          Reads a double from the input.
static int readInt()
          Reads an int from the input.
static java.lang.String readWord()
          Reads a word (delimitted by spaces) from the input as a Java String.
static char[] readWordAsCharArray()
          Reads a word (delimitted by spaces) from the input as an array of char.
static void remove(int index)
          Removes a shape from the window.
static void save(java.lang.String fileName)
          Saves the drawing of the window in a file.
static void sleep(int milliseconds)
          Wait from an amount of time.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Ppl

public Ppl()
Method Detail

initDrawing

public static void initDrawing(java.lang.String s,
                               int x,
                               int y,
                               int w,
                               int h)
Opens a drawing window. Any number of windows can be opened but only the last one can be drawn to.

Parameters:
s - the title of the window.
x - the abscissa of the upper left corner of the window.
y - the ordinate of the upper left corner of the window.
w - the width of the drawing area of the window.
h - the height of the drawing area of the window.

paint

public static int paint(java.awt.Shape shape,
                        java.awt.Color fg,
                        java.awt.Color bg)
Adds a shape to the window.

Parameters:
shape - the shape to be added.
fg - the stroke color.
bg - the fill color.
Returns:
the index of the shape.

remove

public static void remove(int index)
Removes a shape from the window. The index must be one returned from paint or erase and must not have already been removed.

Parameters:
index - the index of the shape.
Throws:
java.util.NoSuchElementException - if no shape of such index is present.

clear

public static void clear()
Removes all shapes from the window.


erase

public static int erase(java.awt.Shape shape)
Adds a white shape to the window. It is more efficient to call remove.

Parameters:
shape - the white shape to draw.
Returns:
the index of the added shape.

drawLine

public static int drawLine(double x1,
                           double y1,
                           double x2,
                           double y2)

drawLine

public static int drawLine(double x1,
                           double y1,
                           double x2,
                           double y2,
                           java.awt.Color color)

drawCircle

public static int drawCircle(double cx,
                             double cy,
                             double r)

paintCircle

public static int paintCircle(double cx,
                              double cy,
                              double r)

paintCircle

public static int paintCircle(double cx,
                              double cy,
                              double r,
                              java.awt.Color fg,
                              java.awt.Color bg)

eraseCircle

public static int eraseCircle(double cx,
                              double cy,
                              double r)

readInt

public static int readInt()
Reads an int from the input.

Returns:
the int read.

hasNextInt

public static boolean hasNextInt()
Tells whether an int is available on input

Returns:
true if an int is available on input.

readWordAsCharArray

public static char[] readWordAsCharArray()
Reads a word (delimitted by spaces) from the input as an array of char.

Returns:
the read word.

readWord

public static java.lang.String readWord()
Reads a word (delimitted by spaces) from the input as a Java String.

Returns:
the read word.

readDouble

public static double readDouble()
Reads a double from the input.

Returns:
the double read.

hasNextDouble

public static boolean hasNextDouble()
Tells whether a double is available on input

Returns:
true if a double is available on input.

readChar

public static char readChar()
Reads a single character from the input. Blanks are first skipped.

Returns:
the character read.

endOfInput

public static boolean endOfInput()
Test for availability of more input.

Returns:
true is no more input is available.

save

public static void save(java.lang.String fileName)
Saves the drawing of the window in a file.

Parameters:
fileName - the file name.

sleep

public static void sleep(int milliseconds)
Wait from an amount of time.

Parameters:
milliseconds - the time in milliseconds.

charFromFile

public static char[] charFromFile(java.lang.String fileName)
reads the whole content of a file and returns it as a char array

Parameters:
fileName - the file name
Returns:
the content of the file
Throws:
java.lang.IllegalArgumentException - when file does not exist or is not readable

charFromFile

public static char[] charFromFile(java.lang.String fileName,
                                  java.lang.String charsetName)
reads the whole content of a file and returns it as a char array

Parameters:
fileName - the file name
charsetName - the name of the charset (UTF-8, US-ASCII, latin1, latin9, ...)
Returns:
the content of the file
Throws:
java.lang.IllegalArgumentException - when file does not exist or is not readable
java.nio.charset.UnsupportedCharsetException - if no support for the named charset is available

failWith

public static void failWith(java.lang.String message)
Throws an new exception with the given message

Parameters:
message - the exception message