public class GraphicsWindow extends Frame
Frame.AccessibleAWTFrame
Window.AccessibleAWTWindow, Window.Type
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
GraphicsWindow(String title,
Image icon,
int width,
int height,
int x,
int y,
boolean doDoubleBuffering)
Create a new
GraphicsWindow to hold graphical output, with possible double buffering for animation. |
GraphicsWindow(String title,
int width,
int height,
int x,
int y)
Create a new
GraphicsWindow to hold graphical
output, without double buffering. |
GraphicsWindow(String title,
int width,
int height,
int x,
int y,
boolean doDoubleBuffering)
Create a new
GraphicsWindow to hold graphical output, with possible double buffering for animation. |
Modifier and Type | Method and Description |
---|---|
void |
copyBack()
Copies the image fron the front buffer to the back buffer.
|
void |
destroy()
Eliminates this
GraphicsWindow object, erasing it from the
screen. |
void |
finalize()
Make sure that everything you drew is properly showing.
|
void |
flip()
Flip the image, so the back buffer is showing.
|
Graphics2D |
getGraphics2D()
Acquire a
Graphics2D object to use to paint. |
int |
getImageHeight()
Get the height of the window's active area.
|
int |
getImageWidth()
Get the width of the window's active area.
|
Graphics2D |
getPen()
Alias for
getGraphics2D() . |
static BufferedImage |
loadImage(String filename)
Static utility to load an image file as a
BufferedImage , to draw later. |
static BufferedImage[] |
loadImageAsTiles(String filename,
int tileSize)
Static utility to load an image file as a 1D array of
BufferedImage s. |
static BufferedImage[][] |
loadImageAsTiles(String filename,
int tileWidth,
int tileHeight)
Static utility to load an image file as a 2D array of
BufferedImage s. |
void |
paint(Graphics pen)
Paints the image to the window, when needed.
|
void |
paintBackground(Color color)
Paint the window a solid color, on both surfaces.
|
static void |
sleep(int millis)
Pause execution for a little while.
|
int |
translateWindowX(int windowX)
Translate the window-relative x coordinate into the active-area-relative x coordinate.
|
int |
translateWindowY(int windowY)
Translate the window-relative x coordinate into the active-area-relative x coordinate.
|
void |
update(Graphics g)
Update method called by the object itself, to reduce flicker.
|
void |
writeAsPNG(String filename)
Outputs the window as a PNG file.
|
addNotify, getAccessibleContext, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, paramString, remove, removeNotify, setBackground, setCursor, setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecorated
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, postEvent, processEvent, processWindowEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFront
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
getFont, postEvent
public GraphicsWindow(String title, int width, int height, int x, int y)
GraphicsWindow
to hold graphical
output, without double buffering. Use this constructor if you
aren't animating anything.title
- the title of the window on your desktopwidth
- the width of the window's contentheight
- the height of the window's contentx
- the initial x-location of the window on the desktopy
- the initial y-location of the window on the desktoppublic GraphicsWindow(String title, int width, int height, int x, int y, boolean doDoubleBuffering)
GraphicsWindow
to hold graphical output, with possible double buffering for animation.title
- the title of the window on your desktopwidth
- the width of the window's contentheight
- the height of the window's contentx
- the initial x-location of the window on the desktopy
- the initial y-location of the window on the desktopdoDoubleBuffering
- if true, double buffering is activatedpublic GraphicsWindow(String title, Image icon, int width, int height, int x, int y, boolean doDoubleBuffering)
GraphicsWindow
to hold graphical output, with possible double buffering for animation.title
- the title of the window on your desktopicon
- the icon to use for this windowwidth
- the width of the window's contentheight
- the height of the window's contentx
- the initial x-location of the window on the desktopy
- the initial y-location of the window on the desktopdoDoubleBuffering
- if true, double buffering is activatedpublic void copyBack()
public void destroy()
GraphicsWindow
object, erasing it from the
screen.public void finalize()
repaint()
. If you are
using double buffering, use flip()
instead.public void flip()
public Graphics2D getGraphics2D()
Graphics2D
object to use to paint.Graphics2D
objectpublic Graphics2D getPen()
getGraphics2D()
. Acquire a Graphics2D
object to use to paint.Graphics2D
objectpublic int getImageHeight()
public int getImageWidth()
public static BufferedImage loadImage(String filename)
BufferedImage
, to draw later.filename
- the name of the image file (JPEG, PNG, GIF, etc.)public static BufferedImage[] loadImageAsTiles(String filename, int tileSize)
BufferedImage
s.
It loads the file, chops it into several images, and returns the set as an array.filename
- the name of the image file (JPEG, PNG, GIF, etc.)tileSize
- the width of each subimagepublic static BufferedImage[][] loadImageAsTiles(String filename, int tileWidth, int tileHeight)
BufferedImage
s.
It loads the file, chops it into several images, and returns the set as an array.filename
- the name of the image file (JPEG, PNG, GIF, etc.)tileWidth
- the width of each subimagetileHeight
- the height of each subimagepublic void paint(Graphics pen)
public void paintBackground(Color color)
color
- the color to paint itpublic static void sleep(int millis)
millis
- number of milliseconds to pausepublic int translateWindowX(int windowX)
public int translateWindowY(int windowY)
public void update(Graphics g)
public void writeAsPNG(String filename)
filename
- the name of the file to be created