|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container java.awt.Window java.awt.Frame javax.swing.JFrame edu.byu.phun2d.Win2D
public class Win2D
This is the basic class for displaying a window on the screen. When you construct a new Win2D object it will automatically open that window at the location that you specified or at a default location and size.
The most important thing to creating a drawing in this window is to add any of the drawable objects to this window using the add(DrawObj) method. To find all of the possible drawable objects look at DrawObj and look at all of its known subclasses. Any objects that you add to this window will be drawn in the order that you add them. This means that the last one added will be the one that is drawn on top of all the others. Please note that creating an drawable object is not enough it must be added to the window or to a Group that is already being drawn.
The origin for drawing in this window is at the center of the window. The positive X axis is to the right and the positive Y axis points up as is done in any geometry book. To see the axes more clearly you can add an AxisObj to your window. This will draw an axis with tic marks so that you can more clearly see where everything is position. The axes generally run from -10 to +10. However, using the scaling functions in Group you can display drawings of any size. The coordinates of the window remain unchanged no matter how big you make the window.
The window has a background color that you can set rather than the default white color.
When you add objects to this window they are actually stored in a Group. You may at some point need to get access to all of the objects being drawn in this window. For that you can use the getSceneGroup() method.
Any object that is being drawn will instantly change in the window if you change something about that object. For example if you change an object's position or color that will instantly appear in the window. Because programs are much faster than people you may want to have your program pause for a moment between changes. This is particularly useful when doing animations. The Win2D.pause(milliseconds) will provide this function.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.BaselineResizeBehavior |
Field Summary |
---|
Fields inherited from class javax.swing.JFrame |
---|
EXIT_ON_CLOSE |
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 | |
---|---|
Win2D(java.lang.String title)
Creates a new window that has no contents and a default background color. |
|
Win2D(java.lang.String title,
int left,
int top,
int width,
int height)
Creates a new window with a specified name and location. |
Method Summary | |
---|---|
void |
add(DrawObj newObj)
This will add a new object to the list of objects to be drawn in this window. |
Group |
getSceneGroup()
This returns a Group that contains all of the objects that have been added to this window. |
static void |
pause(double seconds)
This will pause the program for a specified number of seconds. |
void |
setBackground(Color background)
This will change the background color of the window. |
void |
setBackground(double red,
double green,
double blue)
This will change the background color of the window using the red, green, blue components directly. |
void |
winMouseDown(Point mouseLoc)
This is called whenever the primary mouse button is pressed while over the top of this window. |
void |
winMouseMove(Point mouseLoc)
This is called whenever there is a mouse movement and the primary mouse button is currently pressed. |
void |
winMouseUp(Point mouseLoc)
This is called whenever the primary mouse button is released while the mouse is inside of this window. |
Methods inherited from class javax.swing.JFrame |
---|
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, update |
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.awt.Window |
---|
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, paint, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, toBack, toFront |
Methods inherited from class java.awt.Container |
---|
add, add, add, add, add, addContainerListener, 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, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, 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, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.awt.MenuContainer |
---|
getFont, postEvent |
Constructor Detail |
---|
public Win2D(java.lang.String title)
title
- is the name to be placed on the window bar at the top left.public Win2D(java.lang.String title, int left, int top, int width, int height)
title
- is the name to be places in the window bar at the top left.left
- the location of the left edge of the new window.top
- the location of the top of the window.width
- the width of the window.height
- the height of the window.Method Detail |
---|
public void add(DrawObj newObj)
newObj
- a new object to be drawn.public void setBackground(Color background)
background
- the new background color.public void setBackground(double red, double green, double blue)
red
- the red component of the new background (0.0-1.0)green
- the green component of the new background (0.0-1.0)blue
- the blue component of the new background (0.0-1.0)public static void pause(double seconds)
seconds
- public Group getSceneGroup()
public void winMouseDown(Point mouseLoc)
mouseLoc
- This is the mouse location using the coordinates
of the window which are the same as drawing coordinates. This
is not in pixels.public void winMouseMove(Point mouseLoc)
mouseLoc
- This is the mouse location in drawing coordinates.public void winMouseUp(Point mouseLoc)
mouseLoc
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |