Real Logo
REALbasic Home
X
Thank you for using this example tutorial ... It is not associated with REAL Software.     powered by ... a desire to share
space


Introduction to REALbasic for the Mac


space
Example 2
Learn By Example - Events


My Other RB Pages

Sample RB Projects and Code
My Newbie RB Tutorial - Page One

space
space
space space
Example One: Are You Beautiful ?
by Thomas J. Cunningham

 
  space space

A Whimsical Project
This REALbasic Project Code Here

Let us begin with a fun, whimsical example project. This project introduces, what I refer to, as "housekeeping" aspects of programming. Housekeeping involves controlling and manipulating objects in your project. When you buy a house or condo, the doors open either in or out. The light switch turns on a certain light. Yes, you can change these if you want, but in general, these are details that the architect thought was appropriate. Wouldn't it be "smart" to have an entry light come on as you unlock your door at night? As a builder of applications, we get to create and make some of these decisions for our end users.

A very simple, and yet powerful, programming technique is to hide and unhide objects. The RectControl is the base class for all other control classes (except the graphic control class) and one of its properties is "visible". Visible is a boolean property, that is, it is either true (visible) or not (invisible). So it is very useful to have control objects that can be there for you , as a programmer to use, but not be visible to your end user, who does not need to see them.

For instance, lets say you are working on a game application. And lets say you need to keep track of where one of your little gremlins is on screen using its "left" property. You simply create an instance of a statictext somewhere in your window and everytime your gremlin moves, you show its position like this:

Window1.statictext1.text=str(me.left) // me.left is an integer, so we have to display the string(str) of this number // via our statictext class.

When you are debugging your program in the IDE (and by placing this code in a suitable code editor event), you can simply watch this number change as your little gremlin moves across the screen. When it comes time to let someone else use your program, you can simply initialize its visible property to false, build the program for them and they will never see your statictext.

This project has a simple premise: We are going to ask our user a silly, obvious question. We are going to give them four buttons to push to answer the question. However, when our user tries to answer with the three obvious answers, they are unable to do so because as soon as their mouse cursor enters the button area, it disappears.
My version of this looks like this:
screenshot

The top paragraph and top button are what the user sees when the project is first launched. The user reads the paragraph and clicks on the "begin" button. The bottom paragraph and the bottom four buttons appear and the top paragraph and button dissappear. When the user tries to pick a "good" answer the button dissappears before they can push it. Only the answer I want them to answer remains visible and hence is able to be clicked. A message box is displayed congratulating them on the correct answer, followed by another message box that says "bye", and then we quit.

When these events occur is handled by the built-in events of REALbasic. When the mouse enters a buttons area, its' visible property is set to false, when the mouse exists the area, the visible property is set to true.

This project demonstrates a few simple aspects of programmer housekeeping chores. Anticipating and controlling what our user can and can not do at any time is important, and at times, mysterious and fun.

I hope this helps you.

This REALbasic Project Code Here

Next Example:
Learn By Example - Events

 


Project Code:

Window1.PushButton1.Action:
Sub Action()
msgBox "Congratulations! - You are one of the most beautiful people on the planet - because you are genuine and honest ! ...."
msgBox "Bye - Bye"
quit
End Sub

Window1.PushButton2.
MouseExit:
Sub MouseExit()
me.visible=true
End Sub

Window1.PushButton2.
MouseEnter:
Sub MouseEnter()
me.visible=false
End Sub

Window1.PushButton3.
MouseExit:

Sub MouseExit()
me.visible=true
End Sub

Window1.PushButton3.
MouseEnter:
Sub MouseEnter()
me.visible=false
End Sub

Window1.PushButton4.
MouseExit:
Sub MouseExit()
me.visible=true
End Sub

Window1.PushButton4.
MouseEnter:
Sub MouseEnter()
me.visible=false
End Sub

Window1.PushButton5.
Action:
Sub Action()
statictext2.visible=true
PushButton1.visible=true
PushButton2.visible=true
PushButton3.visible=true
PushButton4.visible=true
PushButton5.visible=false
statictext1.visible=false
End Sub

 


Find This Useful / Not ? Email Me : mauitom@maui.net

Copyright 2001,Thomas J. Cunningham