home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-06-17 | 2.4 KB | 102 lines |
- import java.applet.*;
- import java.awt.*;
-
- public class CrossHair extends Applet
- {
- // User data here
- private Dimension m_dimCursorLoc; // location of cursor
- private boolean m_bDrag; // TRUE->we are currently dragging
-
- public CrossHair()
- {
- }
-
- public String getAppletInfo()
- {
- return "Name: CrossHair\r\n" +
- "Author: Stephen R. Davis\r\n" +
- "Created for Learn Java Now (c)";
- }
-
-
- public void init()
- {
- resize(640, 480);
-
- }
-
- public void destroy()
- {
- }
-
- // CrossHair Paint Handler
- //-----------------------------------------------------------
- public void paint(Graphics g)
- {
- // first build a string containing the current cursor
- // location in the format (xx,yy) and output that
- String sCursorLoc = "("
- + m_dimCursorLoc.width
- + ","
- + m_dimCursorLoc.height
- + ")";
- g.drawString(sCursorLoc, 10, 20);
-
- // now put an x where the cursor is located
- // (make it red if we are dragging and black if not)
- if (m_bDrag)
- {
- g.setColor(Color.red);
- }
- else
- {
- g.setColor(Color.black);
- }
- int nX = m_dimCursorLoc.width;
- int nY = m_dimCursorLoc.height;
- g.drawLine(nX - 2, nY, nX + 2, nY);
- g.drawLine( nX, nY - 2, nX, nY + 2);
- }
-
- public void start()
- {
- }
-
- public void stop()
- {
- }
-
-
-
- // MOUSE SUPPORT:
- //-----------------------------------------------------------
- public boolean mouseDrag(Event evt, int x, int y)
- {
- // set the drag mode to true
- m_bDrag = true;
-
- // record the mouse location
- m_dimCursorLoc = new Dimension(x, y);
-
- // now force a repaint - this will repaint the window
- // with the cross hair at the current mouse location
- repaint();
-
- // returning true indicates that we handled the event
- return true;
- }
-
- // MOUSE SUPPORT:
- //-----------------------------------------------------------
- public boolean mouseMove(Event evt, int x, int y)
- {
- // same as mouseDrag with drag mode turned off
- m_bDrag = false;
- m_dimCursorLoc = new Dimension(x, y);
- repaint();
-
- return true;
- }
-
- }
-