|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
DrawingPanel
public class DrawingPanel
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
static int |
ANY_KEY
|
static int |
DELETE_KEY
|
static int |
DOWN_ARROW_KEY
|
static int |
ENTER_KEY
|
static int |
ESC_KEY
|
static int |
F1_KEY
|
static int |
F10_KEY
|
static int |
F11_KEY
|
static int |
F12_KEY
|
static int |
F2_KEY
|
static int |
F3_KEY
|
static int |
F4_KEY
|
static int |
F5_KEY
|
static int |
F6_KEY
|
static int |
F7_KEY
|
static int |
F8_KEY
|
static int |
F9_KEY
|
static int |
HOME_KEY
|
static int |
INSERT_KEY
|
static int |
LEFT_ARROW_KEY
|
static int |
LEFT_BUTTON
|
static int |
MIDDLE_BUTTON
|
static int |
NO_KEY_PRESSED
|
static int |
PAGE_DOWN_KEY
|
static int |
PAGE_UP_KEY
|
static int |
RIGHT_ARROW_KEY
|
static int |
RIGHT_BUTTON
|
static int |
SHIFT_KEY
|
static int |
TAB_KEY
|
static int |
UP_ARROW_KEY
|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
DrawingPanel(int desiredWidth,
int desiredHeight)
Construct a drawing panel of a given width and height enclosed in a window. |
Method Summary | |
---|---|
void |
closeWindow()
Close the DrawingPanel (actually closes the JFrame) |
void |
copyGraphicsToScreen()
Copy the offscreen graphics buffer to the screen. |
java.awt.Graphics2D |
getGraphics()
Obtain the Graphics object needed to draw on the DrawingPanel's offscreen graphics buffer. |
int |
getKeyHitCode()
Returns a single "key code" for a key that was pressed and released. |
int |
getMouseButton()
Get which mouse button was most recently clicked. |
int |
getMouseClickX(int whichButton)
Get the x coordinate of the mouse's location when the most recent mouse click of the specified button occurred. |
int |
getMouseClickY(int whichButton)
Get the y coordinate of the mouse's location when the most recent mouse click of the specified button occurred. |
int |
getMouseX()
Get the current x coordinate of the mouse. |
int |
getMouseY()
Get the current y coordinate of the mouse. |
int |
getRGB(int x,
int y)
Return an integer representation of the color at a specified pixel location. |
boolean |
isMouseButtonDown(int whichButton)
Determine if a specific mouse button is down at the time of the method call. |
boolean |
keyHasBeenHit(int whichKeyCode)
Has the specified key been hit (pressed and released)? |
boolean |
keyIsDown(int whichKeyCode)
Is the specified key down at this moment in time? |
void |
keyPressed(java.awt.event.KeyEvent e)
Callback method for "key pressed" events (never call explicitly). |
void |
keyReleased(java.awt.event.KeyEvent e)
Callback method for "key release" events (never call explicitly). |
void |
keyTyped(java.awt.event.KeyEvent e)
Callback method for "key typed" events (never used - never call explicitly). |
static java.awt.image.BufferedImage |
loadBitmap(java.lang.String filename)
Load a bitmap image into memory. |
void |
mouseClicked(java.awt.event.MouseEvent e)
MouseInputListener Callback (application never calls this method) |
boolean |
mouseClickHasOccurred(int whichButton)
Determine if a mouse click has occurred. |
void |
mouseDragged(java.awt.event.MouseEvent e)
MouseInputListener Callback (application never calls this method) |
void |
mouseEntered(java.awt.event.MouseEvent e)
MouseInputListener Callback (application never calls this method) |
void |
mouseExited(java.awt.event.MouseEvent e)
MouseInputListener Callback (application never calls this method) |
void |
mouseMoved(java.awt.event.MouseEvent e)
MouseInputListener Callback (application never calls this method) |
void |
mousePressed(java.awt.event.MouseEvent e)
MouseInputListener Callback (application never calls this method) |
void |
mouseReleased(java.awt.event.MouseEvent e)
MouseInputListener Callback (application never calls this method) |
int |
numberOfKeysActive()
Return the number of keys that are currently being pressed on the keyboard. |
void |
run()
Run the GUI drawing panel in a separate thread so that the application that is drawing to the window can be paused and restarted (never called by an application). |
void |
saveGraphics(java.lang.String filename)
Save the current graphics (in the offscreen buffer) to a file. |
void |
setBackground(java.awt.Color c)
Clears the DrawingPanel's graphics window to the specified color. |
void |
setRGB(int x,
int y,
int RGB)
Set the color at a specified pixel location. |
void |
setWindowTitle(java.lang.String name)
Set the windows name -- which appears in the window's header. |
void |
sleep(int millis)
Make your application "sleep" for the specified number of milliseconds. |
void |
waitForKeyHit()
Wait for the user to hit a key on the keyboard -- your application goes to sleep until a key is pressed and released on the keyboard. |
void |
waitForKeyPressed()
Wait for the user to press a key on the keyboard -- your application goes to sleep until a key is pressed. |
void |
waitForMouseClick(int whichButton)
Wait for a mouse click on a specific mouse button (your application goes to sleep until the specific mouse button has been clicked (pressed and released)). |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int LEFT_BUTTON
public static final int MIDDLE_BUTTON
public static final int RIGHT_BUTTON
public static final int NO_KEY_PRESSED
public static final int ANY_KEY
public static final int F1_KEY
public static final int F2_KEY
public static final int F3_KEY
public static final int F4_KEY
public static final int F5_KEY
public static final int F6_KEY
public static final int F7_KEY
public static final int F8_KEY
public static final int F9_KEY
public static final int F10_KEY
public static final int F11_KEY
public static final int F12_KEY
public static final int LEFT_ARROW_KEY
public static final int RIGHT_ARROW_KEY
public static final int UP_ARROW_KEY
public static final int DOWN_ARROW_KEY
public static final int INSERT_KEY
public static final int HOME_KEY
public static final int DELETE_KEY
public static final int PAGE_UP_KEY
public static final int PAGE_DOWN_KEY
public static final int ESC_KEY
public static final int TAB_KEY
public static final int SHIFT_KEY
public static final int ENTER_KEY
Constructor Detail |
---|
public DrawingPanel(int desiredWidth, int desiredHeight)
desiredWidth
- width of paneldesiredHeight
- height of panelMethod Detail |
---|
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void setWindowTitle(java.lang.String name)
name
- title of windowpublic void closeWindow()
public void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved
in interface java.awt.event.MouseMotionListener
public void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered
in interface java.awt.event.MouseListener
public void mouseExited(java.awt.event.MouseEvent e)
mouseExited
in interface java.awt.event.MouseListener
public void mousePressed(java.awt.event.MouseEvent e)
mousePressed
in interface java.awt.event.MouseListener
public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
public void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged
in interface java.awt.event.MouseMotionListener
public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked
in interface java.awt.event.MouseListener
public void keyPressed(java.awt.event.KeyEvent e)
keyPressed
in interface java.awt.event.KeyListener
public void keyReleased(java.awt.event.KeyEvent e)
keyReleased
in interface java.awt.event.KeyListener
public void keyTyped(java.awt.event.KeyEvent e)
keyTyped
in interface java.awt.event.KeyListener
public java.awt.Graphics2D getGraphics()
public void setBackground(java.awt.Color c)
c
- new background colorpublic void copyGraphicsToScreen()
public void sleep(int millis)
millis
- # of millisecondspublic void waitForMouseClick(int whichButton)
whichButton
- which mouse button you want to wait for
(DrawingPanel.LEFT_BUTTON, DrawingPanel.MIDDLE_BUTTON, or DrawingPanel.RIGHT_BUTTON).public boolean mouseClickHasOccurred(int whichButton)
whichButton
- which mouse button you want to check for a click
(DrawingPanel.LEFT_BUTTON, DrawingPanel.MIDDLE_BUTTON, or DrawingPanel.RIGHT_BUTTON).
public boolean isMouseButtonDown(int whichButton)
whichButton
- which mouse button you want to check the status of
(DrawingPanel.LEFT_BUTTON, DrawingPanel.MIDDLE_BUTTON, or DrawingPanel.RIGHT_BUTTON).
public int getMouseButton()
public int getMouseX()
public int getMouseY()
public int getMouseClickX(int whichButton)
public int getMouseClickY(int whichButton)
public void waitForKeyHit()
public boolean keyIsDown(int whichKeyCode)
whichKeyCode
- which key to check
public boolean keyHasBeenHit(int whichKeyCode)
whichKeyCode
- which key to check
public void waitForKeyPressed()
public int getKeyHitCode()
The integer values represents the key that was pressed (and not the upper or lower case of the key).
public int numberOfKeysActive()
If you call the getKeyCode() the number of times returned by this method, you will get the key codes for all keys currently being held down.
public int getRGB(int x, int y)
public void setRGB(int x, int y, int RGB)
x
- x coordinatey
- y coordinateRGB
- colorpublic void saveGraphics(java.lang.String filename)
filename
- name of filepublic static java.awt.image.BufferedImage loadBitmap(java.lang.String filename)
filename
- the name of the bitmap image file (including the .bmp extension)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |