|
This is an excerpt from Java Studio by Example, published by Sun Microsystems Press in June 1998. Java Studio is a visual programming environment not only for end users who do not want to write code, but also for programmers who want to rapidly create prototypes, JavaBeans, or working applications. By saving their Java Studio designs as Beans, programmers can combine designs into larger programs with any development environment that supports JavaBeans. Some of the advantages of using Java Studio for programming include:
The chapter excerpted here describes the user model and the basic parts of Java Studio. This information introduces you to the wiring paradigm in Java Studio, whereby you assemble components and "wire" them together, as well as the range of components that are available with the tool. You'll see the kinds of programs that you can create, as well as how easy it is to bring Beans from other sources into Java Studio. Chapter 2 Java Studio Basics
Java Studio consists of a set of tools and building blocks for designing Java applets and applications. In Part II, you can try ten examples to see how to use Java Studio to create an applet or application. You can even take some of the examples and with some modifications use them immediately in your own work. Some readers will want to dive right into Part II. But if you'd like to know more about the parts of Java Studio and how to use them before you look at the examples, this chapter is for you. Among the features Java Studio provides are:
Java Studio WindowsJava Studio, when started, opens three windows and a startup screen. The startup screen, shown in See Startup Screen , offers some ways of beginning work with Java Studio. You can click on links that will take you to a tutorial, examples, a road map to the product, or a frequently asked questions (FAQ) document. You can dismiss this screen and ask that it not be displayed when you start Java Studio. You can open the screen again anytime by clicking the Duke icon ("Where do I start?") in the Main window. To become familiar with the parts of Java Studio, begin with the Road Map. It consists of pictures of Java Studio windows and question mark icons that you can click to get more information about each part of Java Studio.
Startup ScreenIn addition to the startup screen, three Java Studio windows are opened when you launch the product:
The Design and GUI windows open with introductory text that tells you more about the role of each window. The text disappears when you begin a design by placing the first component in either window. Together, the Design and GUI windows represent the two parts of any program--the way that it appears on the screen and the way that it works. Every component and connection in the design appears in the Design window. Only the user-visible elements appear in the GUI window.
Java Studio Main WindowThe Toolbar and Main MenuThe Main window is the control center of Java Studio. In addition to the component palette, it includes the main menu and the toolbar. The toolbar provides easy access to commands that you will use frequently (See Toolbar).
ToolbarIn the order of their appearance on the toolbar, here are the icons and their actions:
Tool TipsIf you forget the purpose of an icon, move the mouse cursor over it. Java Studio displays the name of the command associated with the icon. Use the same method to see the name of the component icons. As long as an icon on the toolbar is active (that means available), you can read a description of it. When icons or menus appear fuzzy, or what used to be called "grayed out" when monochrome monitors were the rule, that tool or command is not available. Moving the mouse cursor over an icon also causes Java Studio to display a brief description of what the icon does. Look for this description in the footer of the Main window. Java Studio ComponentsJava Studio comes with over forty JavaBeans components that serve as the building blocks for designs. These components are organized in folders within the component palette on the Main window (See Java Studio Main Window). Components fall into the categories GUI (graphical user interface), Data Flow, Computation, Multimedia, Internet, Database, Debug, and User (the kind that you add yourself). The examples in Part II show these components at work in useful designs. There are additional components that were created for Java Studio but that are not part of the product. These are available for free from the Java Studio Web site: http://www.sun.com/studio/ A few of these are used in the examples in Part II. See Importing Components offers a general description of how to import components. Each component is like a small precoded program in itself. For example, you don't have to write the Java programming language statements to create a Button; the Button is already available as a component that you can manipulate with the mouse. You can do a lot with the components right out of the box, so to speak. But chances are you will want to or need to make some changes to these building blocks so that they suit the needs of your design. The process of modifying a component is called customizing. CustomizersAlmost all of the components in Java Studio have a Customizer dialog.1 (Programmers will recognize customizers as interactive views of bean properties.) When you place a component in one of the windows, a Customizer dialog box opens automatically. If you want to change some aspect of the component as you use it, this arrangement may work well for you. You can change this setting so that you must open the customizer yourself. You might prefer the latter method if you tend to lay out most of your design first before you modify the components in it. To change the default behavior of the Customizer dialog:
This command toggles on or off. Click on it again to turn it on.
For the rest of this book, expect menu-command sequences to appear like
this: File Open. The first item is the menu name, followed by the command
from that menu, and finally the submenu, if any, for that command.
There are several ways to open the Customizer dialog for a selected component:
Importing ComponentsIn addition to the components delivered with Java Studio, you can use JavaBeans components from the many vendors and individuals who make them. A set of free JavaBeans components is available to Java Studio users at Sun's Java Studio Web page: http://www.sun.com/studio/. You can import:
If a bean was created in Java Studio or has been used in Java Studio at some time, you import it as described below. The free beans that are available from the Java Studio Web page fall into this category. Choose Import JavaBeans.
If a bean fits the JavaBeans standard but has never been imported or used in Java Studio, you follow the same basic steps, but you might see additional steps in the Import wizard that enable the bean to work with other Java Studio components. Importing a packaged design is very similar to importing a bean. Packaged designs are really just packages of beans and are generated in JAR files, too. To import a packaged design: Choose Import Packaged Design.
Some Notes on Java Studio Components and Web BrowsersThe components that come with Java Studio are based on either the Java development kit ( JDK) version 1.0.2 or JDK 1.1.n. If you use an imported component created with JDK 1.1, Java Studio displays a message ( See JDK 1.1. Warning Message) so that you will know that applets and applications generated from that design will be based on JDK 1.1. Why is this information important? Web browsers that are based on JDK 1.0.2 will display only JDK 1.0.2 applets. Not all Web browsers have caught up with JDK 1.1.n, so applets that include JDK1.1.n components might not display in all browsers. The best way to be sure that your applets will work in any given browser is to test the applet in the browsers where you think it might be used. The appletviewer will display both JDK 1.0.2 and JDK 1.1.n applets.
JDK 1.1. Warning MessageSun's JavaSoft division has created a tool called Java Activator that enables applets to run on Internet Explorer 3.02 or 4 (Windows 95 and Windows NT 4.0), and on Netscape Navigator 3 or 4 (Windows 95, Windows NT 4.0, and Solaris 2.4, 2.5 and 2.6). Java Activator is a plug-in that delivers full JDK 1.1 support to those browsers. It's available for free download from the JavaSoft Web site:
Component CatalogsComponent catalogs are groupings of components. Java Studio includes a catalog by default, but you can import other catalogs. Component catalogs are useful for grouping packaged designs so that you can import them all at once. If you make changes to the Java Studio catalog, say, by removing components in the Customize Palette dialog, or adding them by using the Import menu, you can restore it to its original state by importing it again. The catalog of core components (those that are included with Java Studio) is in: installation_directory/JS/lib/vj/VJSysPalette.cfg (on Solaris) installation_directory\JS\lib\vj\JSysPalette.cfg (on Windows 95 and Windows NT) Creating a Component CatalogThere is no interactive tool in Java Studio for creating a component catalog. You can create a catalog by writing a catalog file and listing all of the components. The system catalog provides an example of how to do this.
Creating a component catalog file is not supported in Java Studio. If you
decide to try to write and use one, be aware that you might get unexpected
results.
The Java Studio core component catalog file illustrates the format for .cfg files:
Importing a Component CatalogTo import a catalog: Choose Import Component Catalog.
By default, every component is checked. This makes it easier to import the entire catalog.
Finding Components in CatalogsTo find a component: Choose Customize Palette to open the Customize Palette dialog box.
Java Studio opens a Find Components dialog box. Enter all or part of a component name, or enter a part of the description, or both.
The Find Components dialog lists all matching components. ConnectorsYou make designs from component building blocks by wiring the components together. Connectors provide a way to exchange information between components. Information comes into a component through an input connectors and is sent out through an output connector. A bidirectional connector can move information in two directions, in and out, through the same connector. Connectors often have names other than "input" or "output" associated with them, for example, "Result of the expression." The name describes the information. "Result of the expression," for example, is the data that results from a calculation. "Result of the expression" is an output connector. To see the name of a connector, move the mouse cursor over a connector to display its name. Triggers are specialized input connectors. Triggers do not move data, they just give the component a signal to perform its operations. You will see the option to add a trigger connector in many of the component customizers. The Java Studio online help says that "components communicate by sending and receiving messages through connectors." You don't need to understand what a message is, or how one is expressed in Java, to use connectors. Think of a message as data sent from one component to another to carry out some action. In some cases, the data is a value (input, output, and bidirectional connectors); in other cases, the data is just a trigger message to start some action (trigger connectors). The simple design illustrated in See An Illustration: Codeless Programming with Java Studio shows a slider controlling the speed of an animation. In that case, a message is simply information from the slider--"I've been activated and here's the setting for the speed"--sent to the animation. The sending of this message is "triggered" by a user moving the slider with a mouse. User actions are typical kinds of events that send a message. Table 2-1 describes the five kinds of connectors. When a component has an icon, the location of the connectors can tell you what kind of connector it is. Each component can have one or more connectors. The Label component doesn't start out with any connectors because you typically use it to label some part of the user interface. It is not always involved in some action in a design. However, you can add connectors to the Label component, and to other components as well, if you need to enable or disable, hide or show, set the label text, or make it respond to an action (like a trigger to send its label to another component). See Placement of Connectors shows the placement of connectors. The illustration uses the Choice component, which is a GUI component that gives the user a drop-down list of items from which to choose. The items in the list are text, or "strings" in programming lingo. In the Choice component the input connector is added when you customize the component to add the ability to enter or select a string (an item in the list). We'll use the Customizer dialog for the Choice component as an illustration in See Adding Connectors below.
Placement of ConnectorsYou'll see how connectors work on a variety of components when you look at the examples in Part II. To see how much you can do with just one of them (an input connector on the Choice component), seeSee An Illustration: Codeless Programming with Java Studio. Adding ConnectorsBy default, the Choice component comes with an output connector. The output connector is for sending to another component the information about what item in the list was selected. The additional connectors are added automatically when you make choices in the Connectors tab of the Choice component Customizer dialog. See Adding Connectors to a Component shows the checkboxes in the Connectors tab. Checking the boxes shown resulted in the additional connectors seen in See Placement of Connectors above. The item not checked is for the input connector that enables the user to select an item from the list: "Select a string value." To give you an idea of how much programming you can do in Java Studio without writing any Java code, we took the customized Choice component in See Placement of Connectors and See Adding Connectors to a Component, added items to the list of choices, and wired it to a text field. See An Illustration: Codeless Programming with Java Studio shows you what we did.
Adding Connectors to a ComponentConnecting ComponentsBy themselves, the components and their connectors are not useful. To make them into a working design, you connect them together by clicking on the appropriate connector and dragging a "wire" to a connector on another component. Deleting ConnectionsTo delete a connection, use any one of several procedures:
See Deleting a Connection shows the pulldown menu with the Disconnect command.
Deleting a ConnectionIllegal ConnectionsSometimes Java Studio will not allow you to wire components together. For example, if you try to wire an output connector from one component to an output connector of another, Java Studio displays a "Connection failed" message. If you import a component and try to wire it to another component that accepts a different kind of data, the connection will fail. An Illustration: Codeless Programming with Java StudioIf you took the Choice component as is, added data items to it, and connected the modified component to a Text Field, you'd have a program. This section shows you how it can be done. (The section See An Example: Customizing and Wiring Components provides a hands-on example for you to try yourself.) In about ten minutes, without writing any code, we created a simple design that:
The result is named ChoiceDesign; you can find it on the companion CD-ROM. The working design in the GUI window is shown in See The Choice Design in the GUI Window.
The Choice Design in the GUI WindowWith this design, the user can select the name of a city from a list. The selected city is displayed in a Text Field. You'd probably want to add a label to the text field so the user understood what was being displayed there. We show you how to do that, too. To create the design:
Each step is described and illustrated next.
The Choice Component in the GUI FolderThe component appears in both windows, and the customizer opens automatically. See The Choice Component As It Appears in Both Windows shows how the component looks in the Design and GUI windows. See The Choice Component As It Appears in Both Windows shows the Customizer dialog for this component.
The Choice Component As It Appears in Both Windows
The Customizer Dialog for the Choice ComponentThe Choice tab contains two fields for entering the items, one for entering the data and the other for entering the form in which to pass its value to another component. (We chose to connect the Choice component to a Text Field for display, and we chose to pass the value exactly as it was entered in the Item field. You are given the two Item fields because there might be times when you want your application to have the selected item send a value other than the name as output. For example, you might want the population of Pittsburgh sent as output when the user selects that city's name from the list.) After each entry, we clicked the Add button. Two additional buttons are available to delete or modify the item. The Delete button removes the selected item from the list. The Modify button reloads the selected item in the Item field, where you can edit it. As we made the entries, the GUI window showed the updated design. The "live" nature of the Java Studio windows means that you can see what you are doing to your design as it happens.
Wiring the Choice Component to the Text FieldOn the Text Field, we simply used the input connector because we wanted the output from the Choice component to input a text value in the Text Field.
Completed DesignThe Labels do not interact with any of the other components in the design, so there is no need to connect them to anything. This is why they have no connectors by default. In other instances, you might want to hide the label under some circumstances or to change its text. In those cases, you could add connectors by using the customizer.
We chose to label the Choice menu itself with the descriptive information "Choose a City:". We labelled the Text Field "Selected City:". If you look at See Customizing the Label, you can see that you enter text for the label without quotation marks. We did include a colon to make it clear that the label applied to what was below it.
Customizing the Label
See Completed User Interface shows the user interface for the completed design.
Completed User InterfaceAn Example: Customizing and Wiring ComponentsIf you'd like to try placing different kinds of components in the Design window and wiring them together, here's a simple example that shows selecting components, using their Customizer dialogs, and wiring them together. (This example is called BasicExample and it is on the Java Studio by Example CD-ROM.) Select the Slider component by clicking on the Slider icon in the GUI folder of the component palette.
The Slider appears in both the Design window and the GUI window, and Java Studio opens a Customizer dialog for it.
In the Standard tab, change the height to 40 and the width to 120.
Notice how the Slider changes as you apply the new values. The GUI window updates as you customize the component.
The Animator component provides a flashy way of showing you how components already contain all of the Java code necessary to make something happen. Without doing anything but pointing and clicking, you have a simple animation program underway.
Connect the output from the Slider to the bottom input connector (Animation Speed) of the Animator. If you want to know what each connector does, pass the mouse cursor over it to get a brief tip. See Getting Information About a Connector shows what the bottom input connector of the Animator does.
Getting Information About a ConnectorYou can try your program at any time in the GUI window. Move the Slider to change the animation speed.
At this point, you might want to make changes in how the completed design looks to a user. You can make some changes to the appearance of an individual component in the Customizer, including the component's size. Changing the size with the mouse is easier and more direct than using the customizer. To change a component's size, click on it to select it and grab one of the blue handles and resize it. To change the overall layout, click on a component in the GUI window and move it to where you want it. The handles on the outside of a component are for resizing. The handle at the center of a component is for dragging the component. You can also drag a component by clicking anywhere in its outside border. See See Handles for Moving or Resizing a Component.
Handles for Moving or Resizing a ComponentYou can create a grid in the GUI window by choosing Layout Show Grid. The Layout menu also contains Set Grid Size and Snap to Grid commands. There are three grid sizes: small, medium, and large. When the Snap to Grid command is on, placing or moving components causes them to line up with the grid. This makes it easier to align components with one another. You'd probably like to add some pieces to start and stop the animation. Move the mouse cursor over the remaining two input connectors on the Animator to see what each does. As you might have guessed, you can add a couple of buttons to your design to start and stop the animation. Except for the brief sidetracks we took to customize the components, you can see how few steps it takes to create a working program. To distribute your work for use outside of Java Studio, you just save the design and generate the Java program. Java Studio Designs Versus ProgramsA Java Studio design is a running program within the context of Java Studio. It's not a program that you can distribute to others until you generate it. When you generate a design, you are generating working Java code that is stored in Java class files and other files that enable you to distribute the program you have created from your design. Getting HelpHelp is available from the Help control (the question mark) on the Java Studio toolbar, from within tools (use the F1 key or click the Help button in the tool's window), and from the Java Studio menu. Context-specific help is available in most windows and dialog boxes. The Help button within a window summons help on that part of Java Studio. From the Help menu, you can open the following types of Help:
The online documentation includes a search capability, too. From anywhere in Help, enter a word or phrase in the Search field and press Return. Java Studio returns a list of the links to pages where that keyword appears. When you follow the link to the page where the search string is located, you'll see the word or phrase highlighted on that page. Finally, there is help on Help. When you are using the Help browser, you'll see that it also has a help menu. This menu offers help on using the Help browser. Help contains links to additional useful resources for programmers using Java Studio. Navigate from the Table of Contents to Developer Resources, or enter these URLs in the Help browser:
The URL for the "JavaBeans Components for Java Studio Cookbook." A guide, with examples, for creating JavaBeans components for Java Studio.
The URL for the APIs for the classes used by Java Studio.
ExamplesThe Help Table of Contents includes an entry for Tutorials and Examples. The tutorials and examples are also available from the Startup Assistant. There is actually just one tutorial: It walks you through the basics of using Java Studio. The step-by-step example shows you how to create an example that creates a currency converter. Finally, the additional examples link takes you to a page that describes the types of examples that are included in an examples directory that is installed with Java Studio and tells you where to find them. If you accepted the default installation directory, the examples are installed in:
C:\Java-Studio1.0\JS\examples
The additional examples page breaks down the examples by what type of design they illustrate, for instance, playing sounds, sending data, handling simple and complex logic, opening and displaying a database, creating applet parameters. Printing HelpYou can print help pages by choosing File Print from the Help browser menu. Java Studio PreferencesThere are a number of things that you can set to reflect your preferences for how you want Java Studio to look or behave. The commands for customizing these parts of Java Studio are found in the View and the Customize menus. Note that the changes you make to the windows are only in effect for the current session. The changes that you make when you customize the palette are in effect even after you quit Java Studio and start it again. Some of the commands on the Customize menu are for customizing components and their connections, not for customizing the working environment of Java Studio itself. However, some of the commands are for setting up your environment. The Customize menu contains these commands for setting preferences:
The View menu contains commands for these settings:
Within the Help browser, there are a few additional preferences that you can set to define whether the Help browser shows or hides: You can also set the font size used in Help browser pages. All of these settings are available from the View menu in the Help browser. Java Studio Files and DirectoriesThe default installation locations for Java Studio, the installed sub directories, and files created and used by Java Studio are described here. Installation DirectoriesFor Windows 95 and Windows NT, the installation program creates these directories:
C:\Java-Studio1.0\....
C:\Java-Studio1.0\Java Studio Group
C:\Java-Studio1.0\JDK
C:\Java-Studio1.0\JS
The installation program also adds Java Studio to the Windows Start menu. You are prompted at installation time to specify a directory other than the default installation directory. Solaris users load a Java Studio tar file and uncompress and untar it in whatever directory they choose. If the installation directory is the home directory, the installed directory structure includes:
$HOME/Java-Studio1.0
$HOME/Java-Studio1.0/JDK
$HOME/Java-Studio1.0/JS
The installation process also creates a directory to store files that Java
Studio uses as you work. If the
C:\Windows\js10
Assuming that the home directory is where you install the product, the Solaris directory is:
$HOME/.js1.0
The Design and Program DirectoriesAs you work with Java Studio, you will create, or Java Studio will generate, the following types of files:
You cannot edit this file, except as a design in Java Studio. You also cannot print it.
For applets, Java Studio generates an HTML file for you. The file contains an
The
You might need to modify the Printing FilesYou can print designs and GUI layouts. To print the design as it appears in the Design window, choose File Print Design. To print the GUI layout of the design, choose File Print GUI. You can also print online help from the Help browser and the page that holds your applet from the Java Studio browser. Choose File Print from the browser menu. SummaryIn this chapter you learned how to use these parts of Java Studio in your work:
As you start using the examples in Part II, keep in mind these tips from this chapter:
1. The exceptions are the 2-Way Splitter and the If component. These components have no customizeable features. Lynn Weaver is a senior technical writer for a human interface and information design group at Sun Microsystems. She has written user information about multimedia products, Java development tools, relational database products, client-server technologies, and object-oriented programming. She is also the author of the Inside Java WorkShop books. Leslie Robertson is an STC (Society for Technical Communication) award-winning freelance writer who has written technical user information about Java development tools, relational database tools, OLAP technologies, query languages, and object-oriented programming for Oracle, Taligent, Sun Microsystems, and other Silicon Valley companies. | |||||||||
|
| ||||||||||||