|
To access the contents, click the chapter and section titles.
Sams Teach Yourself Visual J++ 6 in 21 Days
The first thing you want to take a look at is line 15, where we see that there are two member variables to this class that keep track of the x and y offset to which the two lines of text will draw. At line 40 is the form1_paint() method. The first thing that happens here is that a new font is created. For more information about creating and using fonts, refer to Day 10, Fonts and Text. At lines 44 and 45, the two strings are drawn into the form window. They use the x and y opposite variables. Now, notice at line 48 the start of the HScrollbar controls scrollEvent() method. The x offset variable is set to the new value, and the window is invalidated, then updated. At line 55, the VScrollbar controls scrollEvent() starts. It also simply takes the new value from the ScrollEvent class and sets the y offset variable to this value. It invalidates and then updates the window. Line 69 is where the HScrollbar control is declared and created, and line 70 is where the VScrollbar control is declared and created. At line 87, the HScrollbar controls properties are set. At line 93, the VScrollbar controls properties are set. Toolbar and StatusBar ControlsThese two controls are found in many Windows programs. Toolbars normally appear at the top of an application window, and they provide users with an easy way to perform functions by offering them buttons for one-click operations. Status bars usually are at the bottom of an application window, and they offer an easy way to show users the status of different application items. Toolbar ControlThe Toolbar control is encapsulated in the Toolbar class. This control allows users to easily perform functions in an application. Heres the Toolbar icon that appears in the Toolbox: Several properties are important for toolbars. The first that youll see is the appearance property. This controls whether the toolbar will have a normal appearance (which is 3D) or a flat appearance. The next property is the buttons property. This is a collection of toolbar buttons that make up the toolbar. When you click the small button with the ellipsis in it, the toolbar button editor appears. Then, in the status bar box, you can add your toolbar buttons. When you add a Toolbar control to your form, four lines of default code are added that initialize the control with some default properties. These four lines of code are shown in the next example: toolBar1.setSize(new Point(292, 22)); toolBar1.setTabIndex(0); toolBar1.setDropDownArrows(true); toolBar1.setShowToolTips(true); Most of the methods available in the Toolbar class correspond to toolbar properties. Examples of this are the getAutoSize() method, the getBorderStyle() method, and the getAppearance() method. But with toolbars, youll be mostly interested in the events. The two events youll use more often than any others will be the buttonClick event and the buttonDropDown event. The buttonClick event is triggered whenever a button in the toolbar is clicked by the user. The buttonDropDown event is triggered whenever a button in the drop-down style is pressed. StatusBar ControlStatus bars are areas that are usually displayed at the bottom of an application window. Status bars are used by applications to display various kinds of status information. Heres the StatusBar icon that appears in the Toolbox: Two properties are the most important for status bars. The first one is the dockControl. As with the dockControl for the toolbar, when you select this property, a visual representation of possible docking positions comes up. You can then use this to select a docking position. Another important property is the panels property. When you click the small button with the ellipsis in it, the status bar editor dialog appears. In this, you can add any status bar panels that you want. The next property youll want to pay attention to is the showPanels property. It lets you designate whether the status bar displays panels or whether it displays a single line of text. When you add a status bar to your form, five lines of code that set the StatusBar controls property to default values are added for you. You can see them in the next example: statusBar1.setBackColor(Color.CONTROL); statusBar1.setLocation(new Point(0, 249)); statusBar1.setSize(new Point(292, 24)); statusBar1.setTabIndex(1); statusBar1.setText("statusBar1"); The method you will probably use more often than any other is the setText() method. This sets the text that will appear in the status bar. Of course, the showPanels property has to be set to false to use this method. SummaryWhen you write Visual J++ applications, you have many controls at your disposal. These controls make it very easy to create a user interface. Adding event handling to these controls is just as easy. With the double-click of a mouse button, you can have an event handler for any of the controls events. This ability to easily create user interfaces far surpasses the ability of a Visual C++ programmer to quickly create user interfaces. It puts Visual J++ on the same level with Visual Basic for creating user interfacestheyre both very easy.
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |