public class GraphicsPanel
extends javax.swing.JPanel
package whateverMyPackageIs; import uk.ac.leedsbeckett.oop.GraphicsPanel; import javax.swing.JFrame; public class MainClass { public static void main(String[] args) { GraphicsPanel gp = new GraphicsPanel(); JFrame MainFrame = new JFrame(); MainFrame.add(gp); MainFrame.setSize(640, 480); MainFrame.setVisible(true);; gp.about(); } }
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
GraphicsPanel()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
about()
draws a simple graphic on the canvas
|
void |
clear()
Clears the image contents with the current background colour.
|
void |
drawLine(java.awt.Color color,
int x1,
int y1,
int x2,
int y2)
Draw a line on the image using the given colour bypassing the turtle system
|
void |
forward(int distance)
move the turtle (in the direction it is pointing) by {distance} pixels.
|
java.awt.Color |
getBackground_Col()
gets the background colour used by clear() to fill the panel.
|
java.lang.String[] |
getCommandsIssued()
returns an array of all the commands typed in since run or last reset
|
int |
getDirection() |
java.awt.Graphics |
getGraphicsContext()
returns the graphics context of the HraphicsPanel so it can be draw on
e.g.
|
java.awt.image.BufferedImage |
getImage()
returns a BufferedImage of the current turtle graphic
|
int |
getNumberCommandsissued()
returns the number of issued commands since program started or reset
|
java.awt.Color |
getPenColour()
get the current pen colour
|
int |
getxPos()
get the x position of the turtle
|
int |
getyPos()
get the y position of the turtle
|
void |
insertCommand(java.lang.String command)
insert a string into the command buffer
useful if you add new commands later
|
void |
paint(java.awt.Graphics g)
overridden paint method to handle image updating (do not call directly, use repaint();)
|
void |
penDown()
puts pen down so a line will be drawn when the turtle is moved
|
void |
penUp()
puts pen up so a line will not be drawn when turtle is moved
|
void |
reset()
clear the command buffer, this does not clear the screen
|
void |
setBackground_Col(java.awt.Color background_Col)
gets the background colour used by clear() to fill the panel.
|
void |
setDirection(int direction)
set directions as 0 (north), 90 (east), 180 (south) or 270 (west)
an invalid value results in direction being unchanged
|
void |
setImage(java.awt.image.BufferedImage newImage)
sets the background image to the image passed to it
|
void |
setPenColour(java.awt.Color penColour)
set the current pen colour, further drawing peration will be in the new colour
|
void |
setPreferredSize(int width,
int height) |
void |
setTurtleSpeed(int speed)
sets the speed of the turtle's movement.
|
void |
setxPos(int xPos)
manually set the x position of the turtle (i.e.
|
void |
setyPos(int yPos)
manually set the y position of the turtle (i.e.
|
void |
turnLeft()
turtle is rotated 90 degrees to the left.
|
void |
turnRight()
turtle is rotated 90 degrees to the right.
|
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public GraphicsPanel()
public void drawLine(java.awt.Color color, int x1, int y1, int x2, int y2)
color
- colour of linex1
- x andy1
- y coordinate of start of linex2
- z andy2
- y coordinate of end of linepublic java.awt.Graphics getGraphicsContext()
public int getNumberCommandsissued()
public java.lang.String[] getCommandsIssued()
public void insertCommand(java.lang.String command)
command
- new command to insertpublic void reset()
public java.awt.Color getBackground_Col()
public void setBackground_Col(java.awt.Color background_Col)
background_Col
- the background_Col to set (used when clear() is called.).public int getxPos()
public java.awt.Color getPenColour()
public void setPenColour(java.awt.Color penColour)
penColour
- java coloe constructpublic int getDirection()
public void setDirection(int direction)
direction
- 0,90,180 or 270 or it will be left unchangedpublic void setxPos(int xPos)
xPos
- the xPos to setpublic int getyPos()
public void setyPos(int yPos)
yPos
- the yPos to setpublic java.awt.image.BufferedImage getImage()
public void setImage(java.awt.image.BufferedImage newImage)
newImage
- BufferedImage to set to the backgroundpublic void about()
public void setTurtleSpeed(int speed)
speed
- 0 is fastest 1 for each microsecond of delaypublic void penDown()
public void penUp()
public void turnRight()
public void turnLeft()
public void forward(int distance)
distance
- in pixels to movepublic void clear()
public void paint(java.awt.Graphics g)
paint
in class javax.swing.JComponent
public void setPreferredSize(int width, int height)