Fruit basket program in Boo

  • From: Jamal Mazrui <empower@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Fri, 19 Oct 2007 23:22:19 -0400 (EDT)

From the zip archive at
http://www.EmpowermentZone.com/boo_fruit.zip

This fruit basket program is written in Boo  -- Full source code in the
zip archive and pasted below.  The batch file compile.bat invokes the
command-line compiler for this scripting language.  The resulting
executable, boo_fruit.exe, is about 12K in size.  No other files are
needed to run the program -- as long as the .NET Framework 2.0 is
installed.

Boo borrows syntax from Python, seeks to improve it, and combine strengths
of both static and dynamic languages.  Its home page is at
http://boo.codehaus.org
Boo resources, including the interpreter, compiler, documentation, and
examples are available from there.

I am still learning Boo, but was able to produce a working program by
converting the first C# fruit basket program I did via a web form
available at
http://codeconverter.sharpdevelop.net/Convert.aspx
For comparison, the C# code is available in the file cs_fruit.cs.

Jamal

/*
content of boo_fruit.boo
Fruit Basket program in Boo
Public domain by Jamal Mazrui
*/

namespace MyNamespace

import System.Windows.Forms

// define class inherited from Form
public class MyForm(System.Windows.Forms.Form):

        private lblFruit as Label

        private txtFruit as TextBox

        private lblBasket as Label

        private lbBasket as ListBox

        private btnAdd as Button

        private btnDelete as Button


        public def constructor():
                // define constructor
                // set window title
                self.Text = 'Fruit Basket'
                //this.Width = 328;
                self.Width = 400
                self.Height = 285

                // create two rows of controls with three controls in each
row
                // label, textbox, button and label, listbox, button
                lblFruit = Label()
                lblFruit.Text = '&Fruit:'
                lblFruit.Left = 14
                lblFruit.Top = 14
                lblFruit.Width = 44
                lblFruit.Height = 16

                txtFruit = TextBox()
                txtFruit.Left = 64
                txtFruit.Top = 14
                txtFruit.Width = 200
                txtFruit.Height = 16

                btnAdd = Button()
                btnAdd.Text = '&Add'
                btnAdd.Left = 272
                btnAdd.Top = 14
                btnAdd.Width = 100
                btnAdd.Height = 20
                //  make it the default button
                self.AcceptButton = btnAdd
                btnAdd.Click += self.OnAddClick

                lblBasket = Label()
                lblBasket.Text = '&Basket:'
                lblBasket.Left = 14
                lblBasket.Top = 38
                lblBasket.Width = 44
                lblBasket.Height = 16

                lbBasket = ListBox()
                lbBasket.Left = 64
                lbBasket.Top = 38
                lbBasket.Width = 200
                lbBasket.Height = 200

                btnDelete = Button()
                btnDelete.Text = '&Delete'
                btnDelete.Left = 272
                btnDelete.Top = 38
                btnDelete.Width = 100
                btnDelete.Height = 20
                btnDelete.Click += self.OnDeleteClick

                // add controls to form
                self.Controls.Add(lblFruit)
                self.Controls.Add(txtFruit)
                self.Controls.Add(btnAdd)
                self.Controls.Add(lblBasket)
                self.Controls.Add(lbBasket)
                self.Controls.Add(btnDelete)

                // center form on screen
                self.StartPosition = FormStartPosition.CenterScreen


        // define event handlers for add and delete buttons
        protected def OnAddClick(sender as object, e as System.EventArgs):
                sFruit as string
                sFruit = txtFruit.Text
                if sFruit == '':
                        MessageBox.Show('No fruit to add.', 'Alert')
                else:
                        lbBasket.Items.Add(sFruit)
                        txtFruit.Text = ''
                        lbBasket.SelectedIndex = (lbBasket.Items.Count -
1)
                txtFruit.Focus()


        protected def OnDeleteClick(sender as object, e as
System.EventArgs):
                iFruit as int
                iFruit = lbBasket.SelectedIndex
                if iFruit == (-1):
                        MessageBox.Show('No fruit to delete.', 'Alert')
                else:
                        lbBasket.Items.RemoveAt(iFruit)
                        if iFruit > (lbBasket.Items.Count - 1):
                                iFruit = (lbBasket.Items.Count - 1)
                        lbBasket.SelectedIndex = iFruit
                lbBasket.Focus()


        // define main entry point of application
        public static def Main():
                Application.Run(MyForm())

MyForm.Main()

//End of program

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: