ch.aplu.util
Class GPanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--ch.aplu.util.GPanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.event.KeyListener, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable

public class GPanel
extends javax.swing.JPanel
implements java.awt.print.Printable, java.awt.event.KeyListener

Class to define a very simple graphics window of size 500x500 pixels Subclass of JPanel. It overrides paintComponent in order to draw the graphics automatically from a offline screen buffer The drawing methods perform all drawings in this buffer and automatically repaint it on the screen.

Do not mix with Graphics or Graphics2D methods. Use GWindow instead.

See Also:
GWindow, Serialized Form

Field Summary
static int APPLETFRAME
           
static int EMBEDDED
           
static int STANDARD
           
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GPanel()
          Construct a GPanel and show the window.
GPanel(boolean visible)
          Same as GPanel() with given visibilty.
GPanel(double xmin, double xmax, double ymin, double ymax)
          Construct a GPanel with given window coordinates
GPanel(double xmin, double xmax, double ymin, double ymax, boolean visible)
          Same as GPanel() with given window coordinates and visibility.
GPanel(int mode)
          Construct a GPanel for special purposes.
GPanel(javax.swing.JMenuBar menuBar)
          Same as GPanel() but show given menuBar.
GPanel(javax.swing.JMenuBar menuBar, boolean visible)
          Same as GPanel() with given menuBar and visibilty.
GPanel(javax.swing.JMenuBar menuBar, double xmin, double xmax, double ymin, double ymax)
          Same as GPanel(xmin, xmax, ymin, ymax) with given menuBar.
GPanel(javax.swing.JMenuBar menuBar, double xmin, double xmax, double ymin, double ymax, boolean visible)
          Same as GPanel() with given menuBar, window coordinates and visibility.
GPanel(java.lang.String title)
          Same as GPanel() with given title.
GPanel(java.lang.String title, boolean visible)
          Same as GPanel() with given title and visibilty.
GPanel(java.lang.String title, double xmin, double xmax, double ymin, double ymax)
          Same as GPanel(xmin, xmax, ymin, ymax) with given title.
GPanel(java.lang.String title, double xmin, double xmax, double ymin, double ymax, boolean visible)
          Same as GPanel() with given title, window coordinates and visibility.
GPanel(java.lang.String title, javax.swing.JMenuBar menuBar)
          Same as GPanel() with given title and menuBar.
GPanel(java.lang.String title, javax.swing.JMenuBar menuBar, boolean visible)
          Same as GPanel() with given title, menuBar and visibilty.
GPanel(java.lang.String title, javax.swing.JMenuBar menuBar, double xmin, double xmax, double ymin, double ymax)
          Same as GPanel(xmin, xmax, ymin, ymax) with given title and menuBar.
GPanel(java.lang.String title, javax.swing.JMenuBar menuBar, double xmin, double xmax, double ymin, double ymax, boolean visible)
          Same as GPanel() with given title, menuBar, window coordinates and visibility.
 
Method Summary
 void addExitListener(ExitListener exitListener)
          Register an ExitListener to get a notification when the close button is clicked.
 void applyTransform(java.awt.geom.AffineTransform at)
          Apply the given AffineTransform to offscreen buffer.
 void arc(double radius, double startAngle, double extendAngle)
          Draw an arc with center at the current graph position and given radius in window coordinates.
 java.awt.Color bgColor(java.awt.Color color)
          Set the background color.
 void circle(double radius)
          Draw a circle with center at the current graph position and given radius in horizontal window coordinates.
 void clear()
          Clear the graphics window (fully paint with background color) (and the offscreen buffer used by the window).
 void color(java.awt.Color color)
          Set the current color.
 void disableClose(boolean b)
          Disable/Enable the title bar's closing button
 void dispose()
          Release all used system resources (offscreen buffer, graphics context) and unblock getKeyWait() and getKeyCodeWait().
 void draw(double x, double y)
          Draw a line from current graph position to given window coordinates and set the graph position to the endpoint.
 void draw(java.awt.geom.Point2D.Double pt)
          Draw a line from current graph position to given point (in window coordinates) and set the graph position to the endpoint.
 boolean enableRepaint(boolean doRepaint)
          Enable or disable the automatic repaint in graphics methods.
 void fillArc(double radius, int startAngle, int extendAngle)
          Draw a filled arc with center at the current graph position and given radius in window coordinates.
 void fillCircle(double radius)
          Draw a filled circle with center at the current graph position and given radius in window coordinates.
 void fillGeneralPath(java.awt.geom.GeneralPath gp)
          Fill a figure defined by the given GeneralPath (using window coordinates).
 void fillPolygon(double[] x, double[] y)
          Draw a filled polygon with given corner coordinates in window coordinates.
 void fillPolygon(java.awt.geom.Point2D.Double[] corner)
          Draw a filled polygon with given corner points in window coordinates.
 void fillRectangle(double width, double height)
          Draw a filled rectangle with center at the current graph position and given width and height in window coordinates.
 void fillTriangle(double x1, double y1, double x2, double y2, double x3, double y3)
          Draw a filled triangle with given corner coordinates in window coordinates.
 void fillTriangle(java.awt.geom.Point2D.Double pt1, java.awt.geom.Point2D.Double pt2, java.awt.geom.Point2D.Double pt3)
          Draw a filled triangle with given corners in window coordinates.
 void generalPath(java.awt.geom.GeneralPath gp)
          Draw a figure defined by the given GeneralPath (using window coordinates).
 java.lang.String getAbout()
          Return copywrite information
 java.awt.Color getBgColor()
          Return the current background color.
 char getKey()
          Return the unicode character associated with last key typed.
 int getKeyCode()
          Return the keycode associated with last key pressed.
 int getKeyCodeWait()
          Wait until a key is typed and return the keycode associated with last key pressed.
 char getKeyWait()
          Wait until a key is typed and return the unicode character associated with it.
 int getModifiers()
          Return the modifiers associated with last key pressed.
 java.lang.String getModifiersText()
          Return the modifiers text description associated with last key pressed.
 java.awt.Graphics2D getOffG2D()
          Return the Graphics2D context of the offscreen buffer
 java.awt.geom.Point2D.Double getPos()
          Return reference to point of current graph position (in window coordinates).
 double getPosX()
          Return window coordinate x of current graph position.
 double getPosY()
          Return window coordinate y of current graph position.
 java.lang.String getVersion()
          Return version information
 GWindow getWindow()
          Return a reference to the GWindow used by the GPanel.
 boolean image(java.lang.String imagePath, double x, double y)
          Show the GIF image from given file path at given window coordinates (specifies lowerleft corner of image).
 boolean image(java.lang.String imagePath, java.awt.geom.Point2D.Double pt)
          Show the GIF image from given file path at given point(in window coordinates) (specifies lowerleft corner of image).
 boolean image(java.net.URL imageUrl, double x, double y)
          Show the GIF image from URL at given window coordinates (specifies lowerleft corner of image).
 boolean image(java.net.URL imageUrl, java.awt.geom.Point2D.Double pt)
          Show the GIF image from given URL at given point(in window coordinates) (specifies lowerleft corner of image).
 double imageHeight()
          Return the height (verical size) of the last loaded GIF image (in window coordinates).
 double imageHeight(java.lang.String imagePath)
          Return the height (verical size) of the GIF image from the given path (in window coordinates).
 double imageHeight(java.net.URL imageUrl)
          Return the height (verical size) of the GIF image from the given URL (in window coordinates).
 double imageWidth()
          Return the width (horizontal size) of the last loaded GIF image (in window coordinates).
 double imageWidth(java.lang.String imagePath)
          Return the width (horizontal size) of the GIF image from the given path (in window coordinates).
 double imageWidth(java.net.URL imageUrl)
          Return the width (horizontal size) of the GIF image from the given URL (in window coordinates).
 boolean isReady()
          Test if GPanel is fully initialized.
 boolean kbhit()
          Return true if a key was typed since the last call to getChar() or getCharWait().
 void keyPressed(java.awt.event.KeyEvent evt)
          For internal use only
 void keyReleased(java.awt.event.KeyEvent evt)
          For internal use only
 void keyTyped(java.awt.event.KeyEvent evt)
          For internal use only
 void line(double x1, double y1, double x2, double y2)
          Draws a line with given window coordinates and set the graph position to the endpoint.
 void line(java.awt.geom.Point2D.Double pt1, java.awt.geom.Point2D.Double pt2)
          Draws a line with given points (in window coordinates) and set the graph position to the endpoint.
 void lineWidth(int width)
          Set the current line width in pixels.
 void move(double x, double y)
          Set the current graph position to given window coordinates (without drawing anything).
 void move(int x, int y)
          Same as move(double x, double y) ( Override java.component.move(int x, int y) )
 void move(java.awt.geom.Point2D.Double pt)
          Set the current graph position to given point (in window coordinates) (without drawing anything).
 void paintComponent(java.awt.Graphics g)
          For internal use only.
 void point(double x, double y)
          Draw a single point at the given window coordinates.
 void point(java.awt.geom.Point2D.Double pt)
          Draw a single point at the given pt (in window coordinates).
 void polygon(double[] x, double[] y)
          Draw a polygon with given corner coordinates in window coordinates.
 void polygon(java.awt.geom.Point2D.Double[] corner)
          Draw a polygon with given corner points in window coordinates.
 void pos(double x, double y)
          Same as move(double x, double y)
 void pos(java.awt.geom.Point2D.Double pt)
          Same as move(Point2D.Double pt)
 boolean print(GPrintable gp)
          Same print(gp, scale) with scale = 1.
 boolean print(GPrintable gp, double scale)
          Print the graphics context to an attached printer with the given magnification scale factor.
 int print(java.awt.Graphics g, java.awt.print.PageFormat pf, int pageIndex)
          For internal use only.
 boolean printScreen()
          Same print(gp, scale) with scale = 1.
 boolean printScreen(double scale)
          Print the current screen view to an attached printer with the given magnification scale factor.
 void rectangle(double width, double height)
          Draw a rectangle with center at the current graph position and given width and height in window coordinates.
 void repaint()
          Overrides JPanel's repaint() to inhibit explicit repainting while printing.
 void repaint(int x, int y, int width, int height)
          Overrides JPanel's repaint(int x, int y, int width, int height) to inhibit explicit repainting while printing.
 void resizable(boolean b)
          Determine if the window can be resized
 void setPaintMode()
          Sets the paint mode to overwrite with the current color.
 void setWindow(double xmin, double xmax, double ymin, double ymax)
          Same as window() (deprecated)
 void setWinPosition(int ulx, int uly)
          Same as windowPosition() (deprecated)
 void setXORMode(java.awt.Color c)
          Sets the paint mode to alternate between the current color and the given color.
 void text(char c)
          Draw a char at the current graph position.
 void text(double x, double y, char c)
          Draw a char at the given position without modifying the current graph position.
 void text(double x, double y, java.lang.String str)
          Draw a string at the given position without modifying the current graph position.
 void text(java.lang.String str)
          Draw a string at the current graph position.
 void title(java.lang.String title)
          Set the title in the window's title bar.
 java.awt.Point toUser(double windowX, double windowY)
          Return reference to point in user coordinate of given window coordinates.
 java.awt.Point toUser(java.awt.geom.Point2D.Double windowPt)
          Return reference to point in user coordinate of given point in window coordinate.
 int toUserHeight(double windowHeight)
          Return user coordinates increment y of given window coordinates increment y.
 int toUserWidth(double windowWidth)
          Return user coordinates increment x of given window coordinates increment x.
 int toUserX(double windowX)
          Return user coordinate x of given window coordinate x.
 int toUserY(double windowY)
          Return user coordinate y of given window coordinate y.
 java.awt.geom.Point2D.Double toWindow(int userX, int userY)
          Return reference to point in window coordinates of given user coordinates.
 java.awt.geom.Point2D.Double toWindow(java.awt.Point userPt)
          Return reference to point in window coordinates of given point in user coordinates.
 double toWindowHeight(int userHeight)
          Return window coordinates increment y of given user coordinates increment y.
 double toWindowWidth(int userWidth)
          Return window coordinates increment x of given user coordinates increment x.
 double toWindowX(int userX)
          Return window coordinate x of given user coordinate x.
 double toWindowY(int userY)
          Return window coordinate y of given user coordinate y.
 void triangle(double x1, double y1, double x2, double y2, double x3, double y3)
          Draw a triangle with given corner coordinates in window coordinates.
 void triangle(java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2, java.awt.geom.Point2D.Double p3)
          Draw a triangle with given corners in window coordinates.
 void visible(boolean isVisible)
          Select if GPanel's window is visible or not.
 void window(double xmin, double xmax, double ymin, double ymax)
          Set window coordinates left_x, right_x, bottom_y, top_y
 void windowPosition(int ulx, int uly)
          Set the screen position (in device coordinates)
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STANDARD

public static int STANDARD

EMBEDDED

public static int EMBEDDED

APPLETFRAME

public static int APPLETFRAME
Constructor Detail

GPanel

public GPanel()
Construct a GPanel and show the window. Window coordinates are 0, 1, 0, 1 (0, 0) is lower left


GPanel

public GPanel(int mode)
Construct a GPanel for special purposes.

Use parameter GPanel.APPLETFRAME for an Applet in its own frame.

Use parameter GPanel.EMBEDDED for GPanel which is embedeed in another top-level window (JFrame, JDialog, Browswer window, etc.)
If the GPanel is embedded it's offscreen buffer will be created when the GPanel is displayed. It's said to be "ready" then (may be checked by isReady()). All graphics drawing operation will be blocked if called before the GPanel is ready. (A GPanelNotReadyException is thrown after a timeout of 30 sec)

Window coordinates are 0, 1, 0, 1 (may be changed with window()). (0, 0) is lower left. Set the current graph position to (0, 0).


GPanel

public GPanel(boolean visible)
Same as GPanel() with given visibilty.


GPanel

public GPanel(javax.swing.JMenuBar menuBar)
Same as GPanel() but show given menuBar.


GPanel

public GPanel(javax.swing.JMenuBar menuBar,
              boolean visible)
Same as GPanel() with given menuBar and visibilty.


GPanel

public GPanel(java.lang.String title)
Same as GPanel() with given title.


GPanel

public GPanel(java.lang.String title,
              boolean visible)
Same as GPanel() with given title and visibilty.


GPanel

public GPanel(java.lang.String title,
              javax.swing.JMenuBar menuBar)
Same as GPanel() with given title and menuBar.


GPanel

public GPanel(java.lang.String title,
              javax.swing.JMenuBar menuBar,
              boolean visible)
Same as GPanel() with given title, menuBar and visibilty.


GPanel

public GPanel(double xmin,
              double xmax,
              double ymin,
              double ymax)
Construct a GPanel with given window coordinates. (0, 0) is lower left If you need to draw as accurate as possible on pixels use GPanel(0, 500, 0, 500). Set the current graph position to (0, 0).


GPanel

public GPanel(double xmin,
              double xmax,
              double ymin,
              double ymax,
              boolean visible)
Same as GPanel() with given window coordinates and visibility.


GPanel

public GPanel(javax.swing.JMenuBar menuBar,
              double xmin,
              double xmax,
              double ymin,
              double ymax)
Same as GPanel(xmin, xmax, ymin, ymax) with given menuBar.


GPanel

public GPanel(javax.swing.JMenuBar menuBar,
              double xmin,
              double xmax,
              double ymin,
              double ymax,
              boolean visible)
Same as GPanel() with given menuBar, window coordinates and visibility.


GPanel

public GPanel(java.lang.String title,
              double xmin,
              double xmax,
              double ymin,
              double ymax)
Same as GPanel(xmin, xmax, ymin, ymax) with given title.


GPanel

public GPanel(java.lang.String title,
              double xmin,
              double xmax,
              double ymin,
              double ymax,
              boolean visible)
Same as GPanel() with given title, window coordinates and visibility.


GPanel

public GPanel(java.lang.String title,
              javax.swing.JMenuBar menuBar,
              double xmin,
              double xmax,
              double ymin,
              double ymax)
Same as GPanel(xmin, xmax, ymin, ymax) with given title and menuBar.


GPanel

public GPanel(java.lang.String title,
              javax.swing.JMenuBar menuBar,
              double xmin,
              double xmax,
              double ymin,
              double ymax,
              boolean visible)
Same as GPanel() with given title, menuBar, window coordinates and visibility.

Method Detail

addExitListener

public void addExitListener(ExitListener exitListener)
Register an ExitListener to get a notification when the close button is clicked. (In this case, this is the only action performed when clicking the close button.)


window

public void window(double xmin,
                   double xmax,
                   double ymin,
                   double ymax)
Set window coordinates left_x, right_x, bottom_y, top_y


setWindow

public void setWindow(double xmin,
                      double xmax,
                      double ymin,
                      double ymax)
Same as window() (deprecated)


visible

public void visible(boolean isVisible)
Select if GPanel's window is visible or not. (You may draw into an invisible GPanel and show it afterwards.)


getWindow

public GWindow getWindow()
Return a reference to the GWindow used by the GPanel. (Can be used to access the JFrame used by the Panel because GWindow is derived from JFrame)


repaint

public void repaint()
Overrides JPanel's repaint() to inhibit explicit repainting while printing.

Overrides:
repaint in class java.awt.Component

repaint

public void repaint(int x,
                    int y,
                    int width,
                    int height)
Overrides JPanel's repaint(int x, int y, int width, int height) to inhibit explicit repainting while printing.

Overrides:
repaint in class java.awt.Component

isReady

public boolean isReady()
Test if GPanel is fully initialized. Only used for GPanel.EMBEDDED.
(If GPanel is embedded in an other component any graphics drawing operation must be postponed until the parent component is shown because the GPanel's size is only known at this time.)


paintComponent

public void paintComponent(java.awt.Graphics g)
For internal use only. Implements Printable.print();

Overrides:
paintComponent in class javax.swing.JComponent

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pf,
                 int pageIndex)
For internal use only.

Specified by:
print in interface java.awt.print.Printable

print

public boolean print(GPrintable gp,
                     double scale)
Print the graphics context to an attached printer with the given magnification scale factor. scale = 1 will print on standard A4 format paper. The given gp must implement the GPrintable interface, e.g. the single method void draw(), where all the drawing into the GPanel must occur. A standard printer dialog is shown before printing is started.
Return false, if printing is canceled in this dialog, return true, when print data is sent to the printer spooler. (On some platforms the Java Virtual Machine crashes when changing the printer in this dialog. Use the default printer)
Example:
import ch.aplu.util.*;

public class PrintEx2 extends GPanel implements GPrintable
{
public PrintEx2()
{
draw(); // Draw on screen
print(this); // Draw on printer
}

public void draw()
{
move(0, 0);
draw(1, 0);
draw(1, 1);
draw(0, 1);
draw(0, 0);

line(0, 1, 1, 0);
line(0, 0, 1, 1);
}

public static void main(String[] args)
{
new PrintEx2();
}
}


printScreen

public boolean printScreen(double scale)
Print the current screen view to an attached printer with the given magnification scale factor. A standard printer dialog is shown before printing is started.
Return false, if printing is canceled in this dialog, return true, when print data is sent to the printer spooler.


printScreen

public boolean printScreen()
Same print(gp, scale) with scale = 1.


print

public boolean print(GPrintable gp)
Same print(gp, scale) with scale = 1.


bgColor

public java.awt.Color bgColor(java.awt.Color color)
Set the background color. All drawing are erased. Return the previous color.


getBgColor

public java.awt.Color getBgColor()
Return the current background color.


title

public void title(java.lang.String title)
Set the title in the window's title bar.


toUserX

public int toUserX(double windowX)
Return user coordinate x of given window coordinate x.


toUserY

public int toUserY(double windowY)
Return user coordinate y of given window coordinate y.


toUser

public java.awt.Point toUser(java.awt.geom.Point2D.Double windowPt)
Return reference to point in user coordinate of given point in window coordinate.


toUser

public java.awt.Point toUser(double windowX,
                             double windowY)
Return reference to point in user coordinate of given window coordinates.


toUserWidth

public int toUserWidth(double windowWidth)
Return user coordinates increment x of given window coordinates increment x. Increment is always positive.


toUserHeight

public int toUserHeight(double windowHeight)
Return user coordinates increment y of given window coordinates increment y. Increment is always positive.


toWindowX

public double toWindowX(int userX)
Return window coordinate x of given user coordinate x.


toWindowY

public double toWindowY(int userY)
Return window coordinate y of given user coordinate y.


toWindow

public java.awt.geom.Point2D.Double toWindow(java.awt.Point userPt)
Return reference to point in window coordinates of given point in user coordinates.


toWindow

public java.awt.geom.Point2D.Double toWindow(int userX,
                                             int userY)
Return reference to point in window coordinates of given user coordinates.


toWindowWidth

public double toWindowWidth(int userWidth)
Return window coordinates increment x of given user coordinates increment x. Increment is always positive.


toWindowHeight

public double toWindowHeight(int userHeight)
Return window coordinates increment y of given user coordinates increment y. Increment is always positive.


lineWidth

public void lineWidth(int width)
Set the current line width in pixels.


color

public void color(java.awt.Color color)
Set the current color.


line

public void line(double x1,
                 double y1,
                 double x2,
                 double y2)
Draws a line with given window coordinates and set the graph position to the endpoint.


line

public void line(java.awt.geom.Point2D.Double pt1,
                 java.awt.geom.Point2D.Double pt2)
Draws a line with given points (in window coordinates) and set the graph position to the endpoint.


draw

public void draw(double x,
                 double y)
Draw a line from current graph position to given window coordinates and set the graph position to the endpoint.


draw

public void draw(java.awt.geom.Point2D.Double pt)
Draw a line from current graph position to given point (in window coordinates) and set the graph position to the endpoint.


move

public void move(double x,
                 double y)
Set the current graph position to given window coordinates (without drawing anything).


move

public void move(int x,
                 int y)
Same as move(double x, double y) ( Override java.component.move(int x, int y) )

Overrides:
move in class java.awt.Component

pos

public void pos(double x,
                double y)
Same as move(double x, double y)


move

public void move(java.awt.geom.Point2D.Double pt)
Set the current graph position to given point (in window coordinates) (without drawing anything).


pos

public void pos(java.awt.geom.Point2D.Double pt)
Same as move(Point2D.Double pt)


getPosX

public double getPosX()
Return window coordinate x of current graph position.


getPosY

public double getPosY()
Return window coordinate y of current graph position.


getPos

public java.awt.geom.Point2D.Double getPos()
Return reference to point of current graph position (in window coordinates).


clear

public void clear()
Clear the graphics window (fully paint with background color) (and the offscreen buffer used by the window). Set the current graph position to (0, 0).


circle

public void circle(double radius)
Draw a circle with center at the current graph position and given radius in horizontal window coordinates.


fillCircle

public void fillCircle(double radius)
Draw a filled circle with center at the current graph position and given radius in window coordinates. Use the current color.


rectangle

public void rectangle(double width,
                      double height)
Draw a rectangle with center at the current graph position and given width and height in window coordinates.


fillRectangle

public void fillRectangle(double width,
                          double height)
Draw a filled rectangle with center at the current graph position and given width and height in window coordinates.


arc

public void arc(double radius,
                double startAngle,
                double extendAngle)
Draw an arc with center at the current graph position and given radius in window coordinates. Start angle and extend angle in degrees (zero to east, positive counterclockwise).


fillArc

public void fillArc(double radius,
                    int startAngle,
                    int extendAngle)
Draw a filled arc with center at the current graph position and given radius in window coordinates. Start angle and extend angle in degrees (zero to east, positive counterclockwise).


polygon

public void polygon(double[] x,
                    double[] y)
Draw a polygon with given corner coordinates in window coordinates. (Both arrays must be of equal size.)


polygon

public void polygon(java.awt.geom.Point2D.Double[] corner)
Draw a polygon with given corner points in window coordinates.


fillPolygon

public void fillPolygon(double[] x,
                        double[] y)
Draw a filled polygon with given corner coordinates in window coordinates. (Both arrays must be of equal size.)


fillPolygon

public void fillPolygon(java.awt.geom.Point2D.Double[] corner)
Draw a filled polygon with given corner points in window coordinates.


triangle

public void triangle(double x1,
                     double y1,
                     double x2,
                     double y2,
                     double x3,
                     double y3)
Draw a triangle with given corner coordinates in window coordinates.


triangle

public void triangle(java.awt.geom.Point2D.Double p1,
                     java.awt.geom.Point2D.Double p2,
                     java.awt.geom.Point2D.Double p3)
Draw a triangle with given corners in window coordinates.


fillTriangle

public void fillTriangle(double x1,
                         double y1,
                         double x2,
                         double y2,
                         double x3,
                         double y3)
Draw a filled triangle with given corner coordinates in window coordinates.


fillTriangle

public void fillTriangle(java.awt.geom.Point2D.Double pt1,
                         java.awt.geom.Point2D.Double pt2,
                         java.awt.geom.Point2D.Double pt3)
Draw a filled triangle with given corners in window coordinates.


generalPath

public void generalPath(java.awt.geom.GeneralPath gp)
Draw a figure defined by the given GeneralPath (using window coordinates).


fillGeneralPath

public void fillGeneralPath(java.awt.geom.GeneralPath gp)
Fill a figure defined by the given GeneralPath (using window coordinates).


text

public void text(java.lang.String str)
Draw a string at the current graph position.


text

public void text(char c)
Draw a char at the current graph position.


text

public void text(double x,
                 double y,
                 java.lang.String str)
Draw a string at the given position without modifying the current graph position.


text

public void text(double x,
                 double y,
                 char c)
Draw a char at the given position without modifying the current graph position.


point

public void point(double x,
                  double y)
Draw a single point at the given window coordinates. (Set the current graph position to given point.)


point

public void point(java.awt.geom.Point2D.Double pt)
Draw a single point at the given pt (in window coordinates). (Set the current graph position to given point.)


image

public boolean image(java.lang.String imagePath,
                     double x,
                     double y)
Show the GIF image from given file path at given window coordinates (specifies lowerleft corner of image). Return true if successful. If enableRepaint(false), the image is drawn in offscreen buffer only.


image

public boolean image(java.lang.String imagePath,
                     java.awt.geom.Point2D.Double pt)
Show the GIF image from given file path at given point(in window coordinates) (specifies lowerleft corner of image). Return true if successful. If enableRepaint(false), the image is drawn in offscreen buffer only.


image

public boolean image(java.net.URL imageUrl,
                     double x,
                     double y)
Show the GIF image from URL at given window coordinates (specifies lowerleft corner of image). Return true if successful after the image is completely transfered. If enableRepaint(false), the image is drawn in offscreen buffer only.


image

public boolean image(java.net.URL imageUrl,
                     java.awt.geom.Point2D.Double pt)
Show the GIF image from given URL at given point(in window coordinates) (specifies lowerleft corner of image). Return true if successful after the image is completely transfered. If enableRepaint(false), the image is drawn in offscreen buffer only.


imageWidth

public double imageWidth(java.lang.String imagePath)
Return the width (horizontal size) of the GIF image from the given path (in window coordinates). Return 0, if GIF image is invalid.


imageWidth

public double imageWidth(java.net.URL imageUrl)
Return the width (horizontal size) of the GIF image from the given URL (in window coordinates). Return 0, if GIF image is invalid.


imageWidth

public double imageWidth()
Return the width (horizontal size) of the last loaded GIF image (in window coordinates). Return 0, if GIF image is invalid.


imageHeight

public double imageHeight(java.lang.String imagePath)
Return the height (verical size) of the GIF image from the given path (in window coordinates). Return 0, if GIF image is invalid.


imageHeight

public double imageHeight(java.net.URL imageUrl)
Return the height (verical size) of the GIF image from the given URL (in window coordinates). Return 0, if GIF image is invalid.


imageHeight

public double imageHeight()
Return the height (verical size) of the last loaded GIF image (in window coordinates). Return 0, if GIF image is invalid.


applyTransform

public void applyTransform(java.awt.geom.AffineTransform at)
Apply the given AffineTransform to offscreen buffer.


enableRepaint

public boolean enableRepaint(boolean doRepaint)
Enable or disable the automatic repaint in graphics methods. Return the current state of repainting.
When automatic repaint is disabled, the method repaint() must be called to show the image on the screen.
Useful to avoid flickering while animating an image. If repainting is disabled clear() will only erase the offscreen buffer and not the screen. repaint() should be called after drawing the new situation in order to copy the offscreen buffer to the screen.
While printing, repainting is disabled.


kbhit

public boolean kbhit()
Return true if a key was typed since the last call to getChar() or getCharWait(). (Put the current thread to sleep for 1 ms).


getKey

public char getKey()
Return the unicode character associated with last key typed. Return KeyEvent.CHAR_UNDEFINED if the one character buffer is empty


getKeyCode

public int getKeyCode()
Return the keycode associated with last key pressed. Return KeyEvent.CHAR_UNDEFINED if the one character buffer is empty.


getKeyWait

public char getKeyWait()
Wait until a key is typed and return the unicode character associated with it. Unblocked by calling dispose().


getKeyCodeWait

public int getKeyCodeWait()
Wait until a key is typed and return the keycode associated with last key pressed. Unblocked by calling dispose().


getModifiers

public int getModifiers()
Return the modifiers associated with last key pressed.


getModifiersText

public java.lang.String getModifiersText()
Return the modifiers text description associated with last key pressed.


setPaintMode

public void setPaintMode()
Sets the paint mode to overwrite with the current color.


setXORMode

public void setXORMode(java.awt.Color c)
Sets the paint mode to alternate between the current color and the given color. This specifies that logical pixel operations are performed in the XOR mode, which alternates pixels between the current color and a specified XOR color. When drawing operations are performed, pixels which are the current color are changed to the specified color, and vice versa. Pixels that are of colors other than those two colors are changed in an unpredictable but reversible manner; if the same figure is drawn twice, then all pixels are restored to their original values.


windowPosition

public void windowPosition(int ulx,
                           int uly)
Set the screen position (in device coordinates)


setWinPosition

public void setWinPosition(int ulx,
                           int uly)
Same as windowPosition() (deprecated)


resizable

public void resizable(boolean b)
Determine if the window can be resized


getOffG2D

public java.awt.Graphics2D getOffG2D()
Return the Graphics2D context of the offscreen buffer


dispose

public void dispose()
Release all used system resources (offscreen buffer, graphics context) and unblock getKeyWait() and getKeyCodeWait(). After calling, don't use GPanel instance any more.


disableClose

public void disableClose(boolean b)
Disable/Enable the title bar's closing button


getVersion

public java.lang.String getVersion()
Return version information


getAbout

public java.lang.String getAbout()
Return copywrite information


keyPressed

public void keyPressed(java.awt.event.KeyEvent evt)
For internal use only

Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent evt)
For internal use only

Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent evt)
For internal use only

Specified by:
keyTyped in interface java.awt.event.KeyListener