home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / netrexx.zip / NetRexx / Spectrum.nrx < prev    next >
Text File  |  1997-11-09  |  2KB  |  56 lines

  1. /* A sample graphics stand-alone application for the Java 1.1 platform. */
  2. /* This draws a spectrum in a frame window on the screen, using an
  3.    off-screen image to hold the current picture.  The Java 1.1 event
  4.    model is used to handle the windowClosing event. */
  5.  
  6. options binary                     -- optional, for speed
  7.  
  8. class Spectrum adapter extends Frame implements WindowListener
  9.  
  10.   properties constant
  11.     mywidth=200                    -- our shape
  12.     myheight=300                   -- ..
  13.     glass=Toolkit.getDefaultToolkit.getScreenSize -- screen geometry
  14.  
  15.   properties private
  16.     shadow=Image                   -- where we'll build the image
  17.  
  18.   /* The 'main' method is called when this class is started as an application */
  19.   method main(s=String[]) static
  20.     frame=Spectrum("My Spectrum" Rexx(s))         -- make a titled frame
  21.     -- now size and place it mid-screen
  22.     frame.setBounds((glass.width-mywidth)%2,(glass.height-myheight)%2,-
  23.                     mywidth, myheight)
  24.     frame.show                                    -- and make it visible
  25.  
  26.   /* The constructor for Spectrum passes the title to our superclass,
  27.      and requests that we be told about Window events */
  28.   method Spectrum(s=String)
  29.     super(s)
  30.     addWindowListener(this)
  31.  
  32.   /* update -- called when the display content needs updating */
  33.   method update(g=Graphics)
  34.     shadow=createImage(getSize.width, getSize.height)  -- make new image
  35.     d=shadow.getGraphics                          -- context for graphics
  36.     maxx=getSize.width-1
  37.     maxy=getSize.height-1
  38.     loop y=0 to maxy
  39.       col=Color.getHSBColor(y/maxy, 1, 1)         -- select a colour
  40.       d.setColor(col)                             -- set it
  41.       d.drawLine(0, y, maxx, y)                   -- and fill a slice
  42.     end y
  43.     paint(g)                                      -- paint to screen
  44.  
  45.   /* paint -- called when the window needs to be redrawn, either by
  46.      update or when a window is uncovered */
  47.   method paint(g=Graphics)
  48.     if shadow=null then update(g)                 -- (no image yet)
  49.     g.drawImage(shadow, 0, 0, this) -- copy to screen
  50.  
  51.   /* windowClosing -- called when the window is closed.
  52.      We need to handle this to end the program. */
  53.   method windowClosing(e=WindowEvent)
  54.     exit
  55.  
  56.