home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 May / PCO_5_97.ISO / FilesBBS / OS2 / NETREXX.ARJ / NETREXX.ZIP / NetRexx / Spectrum.nrx < prev    next >
Encoding:
Text File  |  1996-12-12  |  1.9 KB  |  45 lines

  1. /* A sample graphics stand-alone application */
  2. /* This draws a spectrum in a frame window on the screen, using
  3.    and off-screen image to hold the current picture */
  4.  
  5. options binary                     -- optional, for speed
  6.  
  7. class Spectrum extends Frame       -- a window object
  8.  
  9.   shadow=Image                     -- where we'll build the image
  10.  
  11.   /* The 'main' method is called when this class is started as an application */
  12.   method main(s=String[]) static
  13.     frame=Spectrum("My Spectrum" Rexx(s))         -- make a titled frame
  14.     frame.resize(200,200)                         -- size it
  15.     frame.show                                    -- and make it visible
  16.  
  17.   /* The constructor for Spectrum just passes the title to superclass */
  18.   method Spectrum(s=String)
  19.     super(s)
  20.  
  21.   /* Update is called when the display content needs updating */
  22.   method update(g=Graphics)
  23.     shadow=createImage(size.width, size.height)   -- make new image
  24.     d=shadow.getGraphics                          -- context for graphics
  25.     maxx=size.width-1
  26.     maxy=size.height-1
  27.     loop y=0 to maxy
  28.       col=Color.getHSBColor(y/maxy, 1, 1)         -- select a colour
  29.       d.setColor(col)                             -- set it
  30.       d.drawRect(0, y, maxx, y)                   -- and fill a slice
  31.     end y
  32.     paint(g)                                      -- paint to screen
  33.  
  34.   /* Paint is called when the window needs to be redrawn, either by
  35.      update or when a window is uncovered */
  36.   method paint(g=Graphics)
  37.     if shadow=null then update(g)                 -- (no image yet)
  38.     g.drawImage(shadow, 0, 0, this) -- copy to screen
  39.  
  40.   /* We need a handleEvent method to ensure Close works properly */
  41.   method handleEvent(e=Event) returns boolean
  42.     if e.id=Event.WINDOW_DESTROY then exit   -- exit on close
  43.     return super.handleEvent(e)              -- otherwise take default action
  44.  
  45.