[netrexx-course] An Introductory GUI Example

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[netrexx-course] An Introductory GUI Example

General Picture
        At the risk of stealing anyone else's thunder, I've taken the liberty of
pasting my simple little introduction to GUI below. My usual disclaimer is
that everything here expresses only my own misfit ideas and should not be
blamed on anyone wiser.
        To explain this, I'd prefer to avoid the usual UI controls (eg List box,
Label) because apparently Personal Java will not support Swing/JFC (is that
correct?), and I want more look and feel control and lightweight
functionality than the standard AWT controls provide. Besides, a List box
needs an underlying data model based upon the new Collections library
anyway. So I might as well draw things for myself.
        The resulting bevelled box is rather subtle against a charcoal background,
somewhat like WebTV. To appreciate the UI total effect will require many
such elements on the screen, but given the enormous variability in color
and contrast rendition on machines, as well as the diversity of personal
tastes, would you please let me know (privately) how this initial bevel
works for you? (The interior fill details will come later.) Since I'm a
total Java and NetRexx novice, my coding could also benefit from comments.
        Thanks to dIon for showing me how to declare the Frame, which I couldn't
have figured out otherwise. This enabled me to use the explicit option, a
favored discipline in the Visual Basic community.
        The section numbers are intended to enable me to write about the code in
an organized (thematic) fashion for others.
        The capitalization of keywords is intended to make other ex-VB developers
feel at home, and to my mind, this code ought to feel quite welcoming to
them (not to mention readable). Bringing such flexibility in capitalization
to Java development is yet another gratifying little feature of
NetRexx--not a trivial one.
        I avoided the common practice of overstuffing the paint and window-close
handlers with actual code, and figured out how to call other methods from
inside them--increasing the modularity.
        Since I don't see anyone using Dispose() on a regular basis, I don't know
whether it might ever come in useful for garbage collection during
termination.
        It's true you can show someone how to write their first applet using fewer
lines of code, but then you lose some of that advantage explaining how to
embed the applet in a web page, and wind up having to cover
applets-to-application conversion anyhow. Some Java authors feel that
main() ought to be added to programs even if they are intended as applets.
Obviously I am attracted to this idea.
        At face value, this seems like a lot of code just to draw a little box on
the screen. But of course it establishes a foundation upon which lots of
further functionality can be added at relatively little incremental cost,
because of the sheer power of the Java core libraries and the versatile
string processing furnished by NetRexx. So I guess it seems to me that Rexx
bumping into Java is the best thing to happen since chocolate ran into
peanut butter. ;={>

======================================

--
-- 1. Carefully choose class and file name: gpbevel1.nrx
--

-- HFP, Example 2.1
-- v 0.02 June 15, 1998

-- 2. Faster performance; check for typos.
 Options Binary Explicit

-- 3. Import packages, if necessary.

-- 4. Declare class.
 Class gpbevel1 Adapter Extends Frame Implements WindowListener

-- 5. Assign properties.
  Properties Inheritable
        -- Box top.
    gptop       = int 30
        -- Box left.
    gpleft = int 30
        -- Box height.
    gpheight      = int 18
        -- Box width.
    gpwidth       = int 200
        -- Background.
    ui = Color(50, 50, 70)
        -- Bevel hilight.
    lite = Color(80, 80, 150)
        -- Bevel shadow.
    dark = Color(35, 35, 60)

-- 6. Main method (ignored when loaded by a browser).
 Method main(tx=String[]) Static
        -- Declare win explicitly as a frame.
    win = Frame
        -- Construct the window frame.
    win = gpbevel1("Draw box" Rexx(tx))
      -- Set its size and place it mid-screen.
    win.resize(250, 70)
      -- Show it.
    win.setVisible(1)
   -- Implicit end of main method.

-- 7. Construct "This" gpbevel1 object.
 Method gpbevel1(tx=String)
        -- Set background color.
    This.setBackground(ui)
        -- Add a listener for standard events
        -- (specifically, window events).
    addWindowListener(This)
        -- Implicit end of paint method.

-- 8. Intercept two standard window events: the
-- paint-window request and the close-window request.
 Method paint(Region=Graphics)
        doBox(Region)
        -- Implicit end of paint method.

 Method windowClosing(Event=WindowEvent)
        terminate(Event)
        -- Implicit end of close method.

-- 9. Provide custom methods for standard events.
 Method doBox(Region=Graphics)
        -- Select a color and draw a line.
       Region.setColor(dark)
       Region.drawLine(gpleft, gptop, -
                gpleft, gptop + gpheight)
        -- Select a color and draw a line.
        Region.setColor(lite)
        Region.drawline(gpleft + 1, gptop + gpheight, -
                gpleft + gpwidth, gptop + gpheight)
        -- Select a color and draw a line.
        Region.setColor(lite)
        Region.drawLine(gpleft + gpwidth, -
                gptop + gpheight -1, gpleft + gpwidth, gptop)
        -- Select a color and draw a line.
        Region.setColor(dark)
  Region.drawline(gpleft + gpwidth - 1, -
                gptop, gpleft, gptop)
        -- Implicit end of doBox method.

 Method terminate(Event=WindowEvent)
        -- The dispose method is not strictly required -
        -- because Exit collects garbage.
        Event.getWindow().Dispose()
  Exit
        -- Implicit end of terminate method.



----
List Archive: http://www.FindMail.com/list/netrexx-course/ 
To Subscribe: e-mail to [hidden email]
To Unsubscribe: e-mail to [hidden email]
--
Start a FREE E-Mail List at http://www.MakeList.com !

Reply | Threaded
Open this post in threaded view
|

Re: [netrexx-course] An Introductory GUI Example

J. Pedone
Thanks - this is a good example.  Do you mind if I pick it apart with
questions ?  Starting with the most basic:

> Options Binary Explicit

What's explicit ?  I couldn't find this one in the redbook. One of the
NRC command line options (-keep) doesn't seem to work for me either.  

j.



----
List Archive: http://www.FindMail.com/list/netrexx-course/ 
To Subscribe: e-mail to [hidden email]
To Unsubscribe: e-mail to [hidden email]
--
Start a FREE E-Mail List at http://www.MakeList.com !