home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / netrexx.zip / NetRexx / Scribble.nrx < prev    next >
Text File  |  1998-02-10  |  1KB  |  36 lines

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