1. Technology
Send to a Friend via Email

An Introduction to Shoes--Using Shoes for Online Applications


3 of 3

Say it!
An Introduction to Shoes--Using Shoes for Online Applications

Though it's the most common test program, a Hello World application really isn't very exciting, so here's something slightly less trivial to try. For now, don't worry about understanding about "stacks" and "flows"--that's covered here--instead just concentrate on the edit_line, the button and the para. These three elements make up the entire application. When text is entered into the edit line and the button is pressed, the text from the edit line will appear in the para.

 Shoes.app :width => 400, :height => 260 do
   flow do
     @e = edit_line
     button "Say it" do
       @p.clear { para @e.text }
   @p = flow

Elements within the window are created in the same way the para was created in the Hello World application. The edit_line and button are enclosed in a flow to make them appear side by side and, in addition to creating the edit_line normally, it's stored in the @e variable for future reference. The same for @p, the container for the text to be displayed. The button takes a block describing what should be done when it's clicked. This is very simple, as it clears @p of any elements within it and replaces that with a new para containing the text from the edit_line.

If you've used other GUI APIs before (or even if you haven't), you can see how simple all of this is. Shoes aims to make GUI programming fun and interesting. Though you probably won't see commercial Shoes applications or even any "serious" applications written in Shoes, this doesn't mean you shouldn't learn and use it in your projects.

  1. About.com
  2. Technology
  3. Ruby
  4. Graphical User Interfaces
  5. Shoes
  6. Say it!

©2014 About.com. All rights reserved.