|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Window
java.awt.Frame
javax.swing.JFrame
TurtleBox
public class TurtleBox
TurtleBox is a small class which implements a kind of "Logo".
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JFrame |
|---|
JFrame.AccessibleJFrame |
| Nested classes/interfaces inherited from class java.awt.Frame |
|---|
Frame.AccessibleAWTFrame |
| Nested classes/interfaces inherited from class java.awt.Window |
|---|
Window.AccessibleAWTWindow |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
protected double |
angle
|
protected Vector<Vector<Integer>> |
elements
This data structure contains the different elements to move. |
private static int |
LINE
|
private static int |
MOVE
|
protected boolean |
penIsDown
|
protected int |
speed
|
protected JPanel |
surface
|
protected boolean |
turtleHidden
|
protected Point2D.Double |
turtlePos
|
| Fields inherited from class javax.swing.JFrame |
|---|
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled |
| Fields inherited from class java.awt.Frame |
|---|
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 |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface javax.swing.WindowConstants |
|---|
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
TurtleBox(int width,
int height)
Constructs a new TurtleBox |
|
| Method Summary | |
|---|---|
private void |
addElement(int kind,
double x1,
double y1,
double x2,
double y2)
adds an element to the list |
void |
backward(double pixels)
Moves the turtle by some pixels backwards |
void |
clear()
Clear drawing surface (turtle remains at the same position) |
private void |
drawThickLine(Graphics g,
double x1,
double y1,
double x2,
double y2,
int thickness,
Color c)
Method for drawing a thick line in Java. |
private void |
drawTurtle(Graphics2D graphics,
Color innerColor,
Color outerColor)
Draws the turtle with given colors |
void |
forward(double pixels)
Forward the turtle by some pixels |
private double |
getAngle()
Get the actual angle of the turtle (in degrees) |
private void |
gotoXY(double x,
double y)
Positions the turtle to a given place |
void |
hideTurtle()
Hides the turtle |
void |
home()
Set turtle back to home position and orientation |
void |
left(double angle)
Turns the turle left |
static void |
main(String[] args)
The main entry point for executing this program. |
void |
paint(Graphics graphics)
Paints the box with stored elements |
void |
penDown()
Takes the pen down (draw while moving) |
void |
penUp()
Takes the pen up (move without drawing) |
void |
right(double angle)
Turns the turle right |
private void |
setAngle(double angle)
Sets a new angle for the turtle (in degrees) |
void |
setSpeed(int pSpeed)
Sets the drawing speed to a value between 0 and 100 |
void |
showTurtle()
Shows the turtle |
| Methods inherited from class java.awt.Frame |
|---|
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.awt.MenuContainer |
|---|
getFont, postEvent |
| Field Detail |
|---|
private static final int LINE
private static final int MOVE
protected JPanel surface
protected Point2D.Double turtlePos
protected boolean turtleHidden
protected boolean penIsDown
protected double angle
protected int speed
protected Vector<Vector<Integer>> elements
| Constructor Detail |
|---|
public TurtleBox(int width,
int height)
width - the width of the boxheight - the height of the box| Method Detail |
|---|
private void drawThickLine(Graphics g,
double x1,
double y1,
double x2,
double y2,
int thickness,
Color c)
private void drawTurtle(Graphics2D graphics,
Color innerColor,
Color outerColor)
public void paint(Graphics graphics)
paint in class Containerprivate double getAngle()
private void setAngle(double angle)
angle - the angle given in degreepublic void setSpeed(int pSpeed)
pSpeed - the new speed valuepublic void left(double angle)
angle - the angle to turn leftpublic void right(double angle)
angle - the angle to turn rightpublic void hideTurtle()
public void showTurtle()
public void penUp()
public void penDown()
private void addElement(int kind,
double x1,
double y1,
double x2,
double y2)
kind - MOVE or LINEx1,y1,x2,y2 - coords of new elementpublic void forward(double pixels)
pixels - the number of pixels the turtle has to movepublic void backward(double pixels)
pixels - the number of pixels the turtle has to move backwards
private void gotoXY(double x,
double y)
x - the X coordinatey - the Y coordinatepublic void clear()
public void home()
public static void main(String[] args)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||