Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Beginning REALbasic - From Novice To Professional (2006)

.pdf
Скачиваний:
233
Добавлен:
17.08.2013
Размер:
18.51 Mб
Скачать

26

C H A P T E R 1 A N I N T R O D U C T I O N T O R E A L B A S I C

Tip Visual Basic programmers should recognize the PushButton, EditField, and StaticText field as being equivalent to Visual Basic’s Button, TextBox, and Label controls.

At this point, the basic design of the Hello World! application’s GUI is complete. If you want, you can go ahead and run your application by clicking the Run icon in the REALbasic’s Main Toolbar, as Figure 1-13 shows.

Figure 1-13. REALbasic lets you test your application from directly within its IDE.

At this point, you can see REALbasic compile a development version of your application, which it then runs. As you can see, you application has a menu and displays the three controls you added to its main window. However, the application does not have a polished look at this point and it doesn’t do anything. You can take care of addressing these issues in the sections that follow. For now, just exit your application as you would any application that runs on your particular OS. You will be returned to the Window Editor in the REALbasic IDE.

Configuring a Few Properties

The next step in the development of the Hello World! application is to spruce it up a bit by changing the appearance of its window and the controls you placed on it. For starters, click anywhere on the window. When you do, notice that resizing handles appear around the window. Also, you should see the Properties pane, located just to the right of the window Editor, is not populated with information. The information displayed in the Properties pane reflects the current state of Window1. To change an attribute or property of the window, all you have to do is assign a new value to one of the properties displayed in the Properties pane.

For your application, scroll down in the Property pane until you see the Title property, which is located in the Appearance group. Note, the property pane is divided into two columns: the first column displays a listing of all the properties for the selected object and the second column displays each property’s associated value. By default, the Title property is assigned a value of Untitled. Click the Untitled value to select it and replace it with the word “Greetings,” and then press Enter. You should see your application’s title bar has automatically changed to reflect this new value.

C H A P T E R 1 A N I N T R O D U C T I O N T O R E A L B A S I C

27

Next, click the EditField control to select it. The information shown in the Properties pane now reflects the properties associated with the EditField control. You are going to change three properties associated with this control. For starters, in this application, the EditField control is going to be used to display a text string, as opposed to letting the user type a text string into it. To enforce this behavior, scroll down and locate the EditField control’s ReadOnly property and select it.

Next, scroll up and located the Bold property in the Font section and select it. This causes any text displayed to appear in bold, to make it stand out. To set the final property for the EditField control, scroll up and locate the TextColor property in the Appearance section of the Properties pane, and then click the ellipsis icon. When you do, REALbasic displays a color palette, as Figure 1-14 shows. Select a color, such as dark blue, and then click the OK button. The color you selected should now be displayed as the background color in the Value row associated with the TextColor property. The actual background color of the EditField control does not change in the IDE, but it does display as expected in the compiled version of the application.

Figure 1-14. Configuring a color property for a REALbasic control

Now click the StaticText control. The Properties pane now displays properties associated with this control. Locate the Text property, which has a default value of Untitled. Replace this text with My First REALbasic Application. You can do this either by overtyping the current value entry or by clicking the ellipsis icon displayed alongside this value to open the Edit Value window, as Figure 1-15 shows. If necessary, increase the size of the control to see all the text.

28

C H A P T E R 1 A N I N T R O D U C T I O N T O R E A L B A S I C

Figure 1-15. Adding a little descriptive text to your REALbasic application

Next, scroll down and locate the TextAlign property. Click the drop-down list indicator to display the list of available options and select Center.

The last property you need to set is for the PushButton control. Select the control, and then locate its Caption property. Enter a value of Push me. At this point, your application should look like the example you see in Figure 1-16.

Figure 1-16. By changing window and control properties, you can customize the appearance of your application’s GUI.

C H A P T E R 1 A N I N T R O D U C T I O N T O R E A L B A S I C

29

Adding a Little REALbasic Code

Now that your application has the proper look, its time to make it do something. You accomplish this by adding program code. In the case of the Hello World! application, all you need to do is add one line of code to the PushButton control to finish.

To associate programming code with a given control, locate the control in the Windows Editor and double-click it. This opens the Code Editor and provides you with a place to enter the code. Note, just to the left of the code editor you see a browser control that lists all the controls you added to your application. By default, the PushButton1 control’s entry has been expanded and its Action event entry selected.

In REALbasic, actions such as the clicking or movement of the mouse cause events to trigger. You can set up your applications to respond to these events by supplying code statements you want to execute when a specific event is triggered (for example, when the user clicks the PushButton control).

The PushButton control’s Action event executes whenever the user clicks it. Therefore, this makes the Action event the right event for controlling the display of text within the Hello World! application.

Tip Visual Basic programmers should recognize the Action event as being equivalent to Visual Basic’s Click event.

Enter the following text into the Code Editor, exactly as shown.

EditField1.Text = " Hello World! "

Once entered, the Code Editor should look exactly as Figure 1-17 shows. This code is formatted using a specific syntax required by REALbasic. If you do not follow REALbasic’s syntax exactly, an error will result and your application won’t run.

30

C H A P T E R 1 A N I N T R O D U C T I O N T O R E A L B A S I C

Figure 1-17. The Code Editor color codes your code statements to make them easier to read.

This code statement tells REALbasic to set or display the text string “Hello World!” as the EditField’s Text property.

Testing Your Application

If you have not done so yet, now would be a good time to save your application. To do so, click the File menu and select Save. The Save As dialog appears. Type in the name for your application and specify the location where you want to save it, and then click OK. For this application, enter Hello World. In response, REALbasic creates a file named Hello World.rbp.

At this point, the Hello World! application is complete and should be ready to run. To test the application, click the green Run icon located in REALbasic’s main toolbar. REALbasic will respond by compiling a development version of your application. Once the compilation is complete, REALbasic will run your application. Figure 1-18, Figure 1-19, and Figure 1-20 show how your application should look after you start it and click the PushButton labeled Push me, depending on your OS.

C H A P T E R 1 A N I N T R O D U C T I O N T O R E A L B A S I C

31

Figure 1-18. The Hello World! application running on Windows

Figure 1-19. The Hello World! application running on Macintosh

Figure 1-20. The Hello World! application running on Linux

32

C H A P T E R 1 A N I N T R O D U C T I O N T O R E A L B A S I C

Compiling Your Application for Macintosh, Windows, and Linux Execution

If you see an error message when you attempt to test your application, the odds are you mistyped the code statement associated with the PushButton’s Action event. Go back and double-check your typing.

Once everything is working correctly, you are ready to create a stand-alone version—one that can execute outside of REALbasic IDE natively on the OS for which it was created—of your application.

By default, REALbasic compiles your application to run only for the OS you used to run the REALbasic IDE. For example, if you are using a Windows computer, then REALbasic, by default, compiles a stand-alone Windows application. To create a stand-alone application for your particular OS, click the Build icon, located just to the right of the Run icon on REALbasic’s main toolbar. In response, REALbasic generates an executable version of your application stored in the same location where you installed REALbasic. You can run this application by double-clicking it. You can also make as many copies of the application as you want to give away or sell.

If you are using one of the Standard Editions of REALbasic, you may also generate a demo version of your application that will run for five minutes before halting its execution on other REALbasic-supported execution platforms. If you are using REALbasic Professional, then you can compile your application to run on Macintosh, Windows, and Linux.

Before you can use REALbasic to compile your application to run on other execution platforms, you must first tell it which execution platforms you want your application to run on. To do this, you specify which execution platforms you want to compile builds for. You do this by clicking the Project menu and selecting the Build Settings option. Figure 1-21 shows the Build Settings window.

Figure 1-21. Specifying which execution platforms you want to create compiled copies of your application to run on

By default, only the OS you are currently working with is selected. Select the desired target execution platforms, and then click OK. If you click the Build icon in REALbasic’s main toolbar, REALbasic compiles your application for each specified target execution platform, giving each instance of your application the default name of My Application. This probably is not what you want, though. Instead, click the Project tab in the REALbasic IDE, and then click the App item. You can see the properties associated with the APP item are now displayed in the Properties pane. To provide REALbasic with a name for your application on each target execution platform,

C H A P T E R 1 A N I N T R O D U C T I O N T O R E A L B A S I C

33

enter a name for the application in WindowsAppName, MacAppName, MacOSXAppName, MacClassicAppName, and LinuxAppName properties, as appropriate. Now, when you click the Build icon located in main toolbar, REALbasic compiles separate copies of your application, using the names you supplied for each execution platform you selected.

Each of these stand-alone copies of your application will run and look exactly as you saw in Figures 1-18 through 1-20.

Summary

REALbasic is a cross-platform software development tool that provides programmers with a rich and powerful set of features, which stack up against any programming language currently available on Macintosh, Windows, or Linux. With REALbasic, the name of the game is crossplatform portability. REALbasic provides you with all the tools you need to develop powerful applications that can be ported to all three of the major desktop OSs. REALbasic does this without reliance on frameworks or virtual machines, using a programming language that is both easy to learn and master.

C H A P T E R 2

■ ■ ■

Navigating the REALbasic

Integrated Development

Environment

In Chapter 1, you were introduced to REALbasic and many of its capabilities. In this chapter, you build upon this knowledge by learning the ins and outs of working with the REALbasic IDE. This includes learning how to create and manage REALbasic projects, learning how to work with REALbasic Windows and Code Editors, and learning how to take advantage of REALbasic’s integrated Help resources. In addition, you learn how to work with a number of other integrated development environment (IDE) features, including the REALbasic menus, the Bookmarks bar, the Tabs bar, the Editor toolbar, the Project Editor, the Controls and Properties Panes, and the Tips bar. You also learn how to create a custom web browser application. By the time you complete this chapter, you will learn how to

Work with REALbasic editors, menus, and toolbars

Customize REALbasic toolbars

Organize and manage REALbasic projects

Take advantage of REALbasic’s integrated Help resources

Starting REALbasic

As you learned in Chapter 1, you interact with REALbasic by way of its IDE. This includes application development, testing, and compilation. REALbasic’s IDE provides you with all the tools you need to create new applications. These software tools include

Windows Editor

Code Editor

Menu Editor

Compiler

Debugger

35