home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / filesbbs / os2 / netrexx.arj / NETREXX.ZIP / NetRexx / Scribble.nrx < prev    next >
Encoding:
Text File  |  1997-07-02  |  1.2 KB  |  35 lines

  1. /* The 'Scribble' applet, using an Adapter class */
  2.  
  3. class Scribble adapter binary-
  4.                extends Applet-
  5.                implements MouseListener, MouseMotionListener, ActionListener
  6.  last_x=int; last_y=int            -- these record mouse coordinates
  7.  
  8.  
  9.  method init
  10.   addMouseListener(this)           -- we want mouse events ..
  11.   addMouseMotionListener(this)     -- .. and mouse movements
  12.  
  13.   b=Button("Clear")                -- make a button
  14.   b.addActionListener(this)        -- we want to see the button's events
  15.   add(b)                           -- add the button to the applet
  16.  
  17.  
  18.  method mousePressed(m=mouseEvent)
  19.   last_x=m.getX; last_y=m.getY     -- initialize mouse coordinates
  20.  
  21.  
  22.  method mouseDragged(m=mouseEvent)
  23.   g=this.getGraphics               -- get applet's Graphics context
  24.   x=m.getX; y=m.getY               -- get mouse coordinates
  25.   g.setColor(Color.black)
  26.   g.drawLine(last_x, last_y, x, y) -- draw new line segment
  27.   last_x=x; last_y=y               -- save coordinates
  28.  
  29.  
  30.  method actionPerformed(a=ActionEvent)            -- Button pressed
  31.   g=this.getGraphics
  32.   g.setColor(this.getBackground)
  33.   g.fillRect(0, 0, getSize.width, getSize.height) -- clear the window
  34.  
  35.