All Packages This Package Class Hierarchy Class Search Index
java.lang.Object | +----java.awt.Component | +----Pick
Summary |
public class Pick extends java.awt.Component implements java.awt.event.KeyListener, java.awt.event.MouseMotionListener, java.awt.event.MouseListener { // Fields 19 private static final int RAYS; private static final int XYMessageWidth; private static final int XYMessageXPosition; private static final int XYMessageYPosition; private Color activeColour; private static final String alphabet0; private static final String alphabet1; private static final String alphabet2; private Font baseFont; private Bignose bignose; private Bignose colouredBignose; private static final int componentHeight; private static final int componentWidth; private int font1End; private int font1Start; private int font2End; private int font2Start; private int font3End; private int font3Start; // Constructors 1 public Pick(); // Methods 19 public static void main(String[]); private void calculateObject(MouseEvent); public Dimension getPreferredSize(); public Dimension getSize(); public void keyPressed(KeyEvent); public void keyReleased(KeyEvent); public void keyTyped(KeyEvent); public void mouseClicked(MouseEvent); public void mouseDragged(MouseEvent); public void mouseEntered(MouseEvent); public void mouseExited(MouseEvent); public void mouseMoved(MouseEvent); public void mousePressed(MouseEvent); public void mouseReleased(MouseEvent); public void paint(Graphics); private void paintScene(Graphics); private void updateKeyPressed(String, KeyEvent); private void updateMouseEvent(String, MouseEvent); private void updateXYPosition(String, int, int); }
|
Creates a new Class that extends the java.awt.Component class. This means that we will inherit various data and methods from this class. The Component is the basic drawing class for graphics.
This class uses the new AWT event model and implements the KeyListener MouseMotionListener and MouseListener interfaces to capture these events and do something with them.
|
It should look like:
|
See Also: KeyListener, MouseMotionListener, MouseListener
Fields |
· alphabet0 | Summary | Top |
private static final String alphabet0
· alphabet1 | Summary | Top |
private static final String alphabet1
· alphabet2 | Summary | Top |
private static final String alphabet2
The strings of characters displayed on the screen.
· XYMessageXPosition | Summary | Top |
private static final int XYMessageXPosition
The x coordinate of the first message printed about the current cursor position
· XYMessageYPosition | Summary | Top |
private static final int XYMessageYPosition
The y coordinate of the first message printed about the current cursor position
· XYMessageWidth | Summary | Top |
private static final int XYMessageWidth
The width of the first message printed about the current cursor position
· componentWidth | Summary | Top |
private static final int componentWidth
The width of the component as a constant.
· componentHeight | Summary | Top |
private static final int componentHeight
The height of the component as a constant.
· RAYS | Summary | Top |
private static final int RAYS
An integer constant which indicates how many rays there are on the star.
· font1Start | Summary | Top |
private int font1Start
The y coordinate of the start of the first font demonstration. This is used to determine its upper and lower bounds for picking.
· font1End | Summary | Top |
private int font1End
The y coordinate of the end of the first font demonstration. This is used to determine its upper and lower bounds for picking.
· font2Start | Summary | Top |
private int font2Start
The y coordinate of the start of the second font demonstration. This is used to determine its upper and lower bounds for picking.
· font2End | Summary | Top |
private int font2End
The y coordinate of the end of the second font demonstration. This is used to determine its upper and lower bounds for picking.
· font3Start | Summary | Top |
private int font3Start
The y coordinate of the start of the third font demonstration. This is used to determine its upper and lower bounds for picking.
· font3End | Summary | Top |
private int font3End
The y coordinate of the end of the third font demonstration. This is used to determine its upper and lower bounds for picking.
· baseFont | Summary | Top |
private Font baseFont
The Font which is the default when this application runs.
See Also: Font
· activeColour | Summary | Top |
private Color activeColour
The active drawing colour for the messages. This is changed by button clicks.
See Also: Color
· bignose | Summary | Top |
private Bignose bignose
This class just encapsulates the data and painting attributes for a big Nose.
See Also: Bignose
· colouredBignose | Summary | Top |
private Bignose colouredBignose
This class just encapsulates the data and painting attributes for a big Nose.
See Also: Bignose
Constructors |
· Pick | Summary | Top |
public Pick()
Our constructor creates two instances of a Bignose object. These will later be used to paint the bignoses. It also sets the two drawing colours of the bignose.
The super() constructor will be called by default. This will construct the component we extend from.
We request the focus otherwise we will not get Key events.
The new AWT event model is also used via the adding of Listeners for Keys, Mouse and MouseMotion events.
See Also: Bignose, setColours, requestFocus, addKeyListener, addMouseListener, addMouseMotionListener
Methods |
· getSize | Summary | Top |
public Dimension getSize()
Returns the size of this component. Just returns our size.
Uses the constants rather than hard wired values.
- Overrides:
- getSize in class Component
See Also: Dimension
· getPreferredSize | Summary | Top |
public Dimension getPreferredSize()
Returns the preferred size of this component. Just calls getSize().
- Overrides:
- getPreferredSize in class Component
See Also: getSize
· paintScene | Summary | Top |
private void paintScene(Graphics graphics)
Our paintScene method will erase the drawing area to the background colour, and then set the drawing colour for the various objects to be drawn on the screen.
The XColour class is used to give "named" colours a la the X11 colour naming system.
Parameter Description graphics The graphics of the drawable surface.
See Also: getSize, requestFocus, getBackground, getForeground, paint, XColour, Color, Graphics, setColor, drawRect, fillRect, drawArc, fillArc, drawLine, drawPolyline, drawString, setFont, getFontMetrics, getHeight, getName, Bignose, paint, getDefaultToolkit, sync
· paint | Summary | Top |
public void paint(Graphics graphics)
Our paint method simply calls a private painting method and then syncs the graphics.
Parameter Description graphics The graphics of the drawable surface.
- Overrides:
- paint in class Component
See Also: getDefaultToolkit, sync
· updateXYPosition | Summary | Top |
private void updateXYPosition(String string, int x, int y)
This method is used to print the cursor position message.
It takes a string which indicates whether it was a move or a drag. It also takes the (x,y) position of the cursor.
Parameter Description string The message string to print out. x The x coordinate of the Mouse Motion event y The y coordinate of the Mouse Motion event
See Also: Graphics, setFont, setColor, fillRect, drawString, getFontMetrics, getHeight
· mouseDragged | Summary | Top |
public void mouseDragged(MouseEvent e)
This public method is called from the new Event system when the appropriate mouse Drag motion event is posted.
The method simply calls the private updateXYPosition method to form and print the message.
Parameter Description e the event which caused the invocation.
- Implements:
- mouseDragged in interface MouseMotionListener
See Also: updateXYPosition
· mouseMoved | Summary | Top |
public void mouseMoved(MouseEvent e)
This public method is called from the new Event system when the appropriate mouse Move motion event is posted.
The method simply calls the private updateXYPosition method to form and print the message.
Parameter Description e the event which caused the invocation.
- Implements:
- mouseMoved in interface MouseMotionListener
See Also: updateXYPosition
· updateKeyPressed | Summary | Top |
private void updateKeyPressed(String string, KeyEvent key)
This method is used to print the key event message.
It takes a string which indicates whether it was a press or a release. It also takes the Event to print out various modifiers.
Parameter Description string The message string to print out. key The key event which caused the event.
See Also: Graphics, setFont, setColor, fillRect, drawString, getFontMetrics, getHeight
· keyTyped | Summary | Top |
public void keyTyped(KeyEvent e)
This public method is called from the new Event system when the appropriate Key Typed event is posted (a key press followed by a key release).
The method test to see if the letter 'q' was pressed and exits if so.
Parameter Description e the event which caused the invocation.
- Implements:
- keyTyped in interface KeyListener
See Also: exit
· keyPressed | Summary | Top |
public void keyPressed(KeyEvent e)
This public method is called from the new Event system when the appropriate Key Pressed event is posted.
The method simply calls the private updateKeyPressed method to form and print the message.
Parameter Description e the event which caused the invocation.
- Implements:
- keyPressed in interface KeyListener
See Also: updateKeyPressed
· keyReleased | Summary | Top |
public void keyReleased(KeyEvent e)
This public method is called from the new Event system when the appropriate Key Released event is posted.
The method simply calls the private updateKeyPressed method to form and print the message.
Parameter Description e the event which caused the invocation.
- Implements:
- keyReleased in interface KeyListener
See Also: updateKeyPressed
· calculateObject | Summary | Top |
private void calculateObject(MouseEvent mouse)
This method is used to calculate the object under the cursor when the mouse button is pressed. It takes a MouseEvent to get the current (x,y) position. It prints out the name or type of the object.
Parameter Description e the event which caused the invocation.
· updateMouseEvent | Summary | Top |
private void updateMouseEvent(String string, MouseEvent mouse)
This method is used to print the mouse press event message.
It takes a string which indicates whether it was a press, release click, enter or an exit. It also takes the Event to print out various modifiers.
Parameter Description string The message string to print out. key The Mouse event which caused the event.
See Also: Graphics, setFont, setColor, fillRect, drawString, getFontMetrics, getHeight
· mousePressed | Summary | Top |
public void mousePressed(MouseEvent e)
This public method is called from the new Event system when the appropriate mouse Pressed event is posted.
The modifiers are obtained (these contain the key modifiers for when the mouse button was pressed) to obtain which button was pressed.
If the Right Mouse Button was pressed then the object under the current cursor position is reported. (Right Mouse Button = modifiers & Event.META_MASK).
If the Left Mouse Button was pressed then the drawing colour for messages is changed to red. (Left Mouse Button = button unmodified).
If the Middle Mouse Button was pressed then the drawing colour for messages is changed to blue. (Middle Mouse Button = modifiers & Event.ALT_MASK).
Note that an N-button mouse is catered for via a single button plus modifiers.
The method then calls the private updateMouseEvent method to form and print the message.
Parameter Description e the event which caused the invocation.
- Implements:
- mousePressed in interface MouseListener
See Also: calculateObject, getModifiers, updateMouseEvent
· mouseReleased | Summary | Top |
public void mouseReleased(MouseEvent e)
This public method is called from the new Event system when the appropriate mouse Released event is posted.
The method then calls the private updateMouseEvent method to form and print the message.
Parameter Description e the event which caused the invocation.
- Implements:
- mouseReleased in interface MouseListener
See Also: updateMouseEvent
· mouseEntered | Summary | Top |
public void mouseEntered(MouseEvent e)
This public method is called from the new Event system when the appropriate mouse entered an window event is posted.
The method then calls the private updateMouseEvent method to form and print the message.
Parameter Description e the event which caused the invocation.
- Implements:
- mouseEntered in interface MouseListener
See Also: updateMouseEvent
· mouseExited | Summary | Top |
public void mouseExited(MouseEvent e)
This public method is called from the new Event system when the appropriate mouse exited an window event is posted.
The method then calls the private updateMouseEvent method to form and print the message.
Parameter Description e the event which caused the invocation.
- Implements:
- mouseExited in interface MouseListener
See Also: updateMouseEvent
· mouseClicked | Summary | Top |
public void mouseClicked(MouseEvent e)
This public method is called from the new Event system when the appropriate mouse clicked event is posted.
The method then calls the private updateMouseEvent method to form and print the message.
Parameter Description e the event which caused the invocation.
- Implements:
- mouseClicked in interface MouseListener
See Also: updateMouseEvent
· main | Summary | Top |
public static void main(String[] args)
Test the new Component. Create a Frame to hold the component, create the component and then set it's foreground and background colour. Add the component to the Frame and then pack the Frame. Then make it all visible on the screen.
Parameter Description args The arguments passed in from the invocation of this java class. First element is NOT name of program.
See Also: Frame, setBackground, setForeground, add, pack, setVisible
All Packages This Package Class Hierarchy Class Search IndexFreshly brewed Java API Documentation automatically generated with polardoc Version 1.0.7