Debugging Java programs in the Distributed Application Developer s Guide. For more information on CodeInsight and syntax highlighting, see The JBuilder environment in Building Applications with JBuilder. Debugging You may debug a file or a whole project. You may compile before debugging or not. To choose whether to compile before debugging, choose Project|Project Properties and select the Run tab. Use the Compile Before Debugging check box at the bottom of the dialog. In JBuilder Professional, you can choose whether and how to use Smart Step. In JBuilder Enterprise, you can choose to enable remote debugging and to make appropriate settings. To do either of these, choose Project|Project Properties and select the Debug tab. To debug a file, right-click on it in the project pane and choose Debug from the context menu. To set a breakpoint in the source code, either choose Run|Add Breakpoint, click in the gray margin to the left of an executable line of code in the source file, or use the keystroke sequence for your chosen editor emulation. To debug a project, follow these steps: 1 Open your project. 2 Select Project|Project Properties. Choose the Run tab and decide whether JBuilder should compile before debugging. 3 To set a breakpoint in the source code, either choose Run|Add Breakpoint, click in the gray margin to the left of an executable line of code in the source file, or use the keystroke sequence for your chosen editor emulation. 4 Choose Run|Debug Project or click the Debug icon in the toolbar. The compiler and debugger work the same way on both files and projects: If you have set JBuilder to compile before debugging, then any compiler errors will show on the compiler page in the message pane at the bottom of the AppBrowser. You may click the error message to go to the relevant line of code. If you have disabled the compiler, or if there are no errors, the debugger will show in the message pane. Use your tool tip on the left-hand tabs to see the kinds of information the debugger provides: 7-4 Learning Java with JBuilder
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services
Running Java programs To compile the source files for an application or applet, follow these steps: 1 Open a project. 2 Do one of the following in the project pane: To compile an application, select the project node (.jpr or .jpx extension). To compile an applet, select the HTML file that calls the applet. 3 Then, do one of the following: Choose Project|Make Project. Right-click a node and choose Make. Note If you haven t already set the runnable class, the Run page of the Project Properties dialog box appears. Browse to the runnable class and select it to continue compiling. Compiler error messages are displayed in the message pane below the AppBrowser content pane. Select an error message to display the relevant source code. To get help on an error message, select the error message in the message pane and press F1. To learn about error messages in JBuilder, see Error and warning messages in Building Applications with JBuilder. For more information, see Compiling Java programs in Building Applications with JBuilder. Running Java programs Running a project runs the main class of that project file. If a main class has not yet been selected, then when you try to run it, a dialog box appears so you can make the selection. If you created your file using the Application wizard or the Applet wizard, the main class is automatically 7-2 Learning Java with JBuilder
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services
Chapter 7 Compiling and running Java programs The JBuilder compiler has full support for the Java language, including inner classes and Java Archive (JAR) files. You can compile (or make ) from within the IDE. With JBuilder Professional and Enterprise, you can also compile from the command line using bmj(Borland Maker for Java) or bcj (Borland Compiler for Java). For more information on the command line tools, see Using the command line tools in Building Applications with JBuilder. The Run command compiles and runs projects, individual .java files (such as JSPs), or HTML applets. JBuilder s integrated debugger allows you to run a project or file with or without debugging it. In JBuilder Professional and Enterprise, you can set runtime configurations that are appropriate for the kind of file or program that you want to run, whether it s an application, an applet, a JSP, a servlet, or an EJB. Compiling Java programs A Java compiler reads Java source files, determines which additional files need to be compiled, and produces the Java program in the form of .class files containing bytecodes that are the machine code for the Java Virtual Machine (VM). Compiling produces a separate .class file for each class declaration and interface declaration in a source file. When you run the resulting Java program on a particular platform, the Java interpreter for that platform runs the bytecode contained in the .class files. Compiling and running Java programs 7-1
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services
Designing layouts with layout managers Layout managers give you the following advantages: Correctly positioned components that are independent of fonts, screen resolutions, and platform differences. Intelligent component placement for containers that are dynamically resized at runtime. Ease of translation with different sized strings. If a string increases in size, the components stay properly aligned. JBuilder provides the following layout managers from Java AWT and Swing: BorderLayout FlowLayout GridLayout CardLayout GridBagLayout Null JBuilder Professional and Enterprise also provide these custom layouts: XYLayout, which keeps components you put in a container at their original size and location (x,y coordinates) PaneLayout, used to divide a container into multiple panes VerticalFlowLayout, which is very similar to FlowLayout except that it arranges the components vertically instead of horizontally BoxLayout2, a bean wrapper class for Swing s BoxLayout, which allows it to be selected as a layout in the Inpsector OverlayLayout2, a bean wrapper class for Swing s OverlayLayout, which allows it to be selected as a layout in the Inspector You can create custom layouts of your own, or experiment with other layouts such as those in the java.awt classes, new or third-party layout managers. Many of these are public domain on the Web or accessible to members of the Open Source community. If you want to use a custom layout in the UI designer, you may have to provide a Java helper class file to help the UI designer use the layout. Most UI designs use a combination of layouts, nesting different layout panels within each other. For more information, see Using layout managers in Building Applications with JBuilder. 6-6 Learning Java with JBuilder
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services
Designing layouts with layout managers For more information, see Designing a user interface in Building Applications with JBuilder. Using the Inspector, you can: Set the initial property values for components in a container and for the container and its layout manager (initialization code). Create, name, and delete event listeners in a container that will receive events from the component in the container (event handling code). Save text property String values to a ResourceBundle, or revert a resourced String back to a String constant. Change the level of properties exposed in the Inspector. Expose a property as a class level variable so you can change it in the Inspector. Any changes you make in the Inspector are reflected immediately in the source code and in the UI designer. For more information, see Handling events in Building Applications with JBuilder. Opening the Inspector To display the Inspector, 1 Select a Java file in the project pane and press Enter to open the file in the content pane. 2 Select the Design tab at the bottom of the AppBrowser to access the designer. The Inspector is displayed at the right of the content pane. 3 Adjust the width of the Inspector by dragging its left border. For more information, see Using the Inspector in Building Applications with JBuilder. Designing layouts with layout managers A program written in Java might be deployed on more than one platform. If you were to use classic UI design techniques that specify absolute positions and sizes for your UI components, the UI might not look as you intended on all platforms. What looks fine on your development system might be unusable on another platform. To solve this problem, Java provides a system of portable layout managers. Building a user interface 6-5
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services
Setting component properties and events To return to the UI designer, double-click any component in the UI folder of the component tree. For more information, see Designing menus in Building Applications with JBuilder. Setting component properties and events The Inspector in the UI designer allows you to visually edit component properties and attach code to component events. You can make changes to the properties and events in the Inspector and the appropriate code is automatically inserted into your source code. 6-4 Learning Java with JBuilder
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services
Designing menus Viewing a file 1 Double-click a Java file in the project pane. The file opens in the source editor in the content pane. 2 Select the Design tab at the bottom of the content pane. The file changes to the design view, or the designer. The component palette and the Inspector become available. Adding and manipulating components Click a component in the component palette to select it. Click either in the designer or on the component s parent in the structure pane to drop the chosen component into the designer. Use the component tree in the structure pane to keep track of where your UI components are in relation to each other. Cut and paste components in the component tree to stack and nest them the way you want them. Select the container you want to apply a layout manager to, then select layout in the Inspector to choose and apply the desired layout manager. Double-click the right column fields of the Inspector to view available values or activate text fields. Note JBuilder keeps the designer and the Java source code synchronized. When you change the design in the UI designer, JBuilder automatically updates the source code, and when you change the source code, the change is reflected in the UI designer. For more information, see JBuilder s visual design tools in Designing a user interface in Building Applications with JBuilder. Designing menus JBuilder includes a menu designer that makes it easy to create menus. You can visually design both drop-down and pop-up menus. To access JBuilder s menu designer, 1 Double-click a Java file in the project pane to open it. 2 Select the Design tab at the bottom of the content pane to change to the designer. 3 Add a menu component by clicking a menu component from the component palette then clicking in your design. 4 Double-click the new menu component in the component tree to activate the menu designer. Building a user interface 6-3
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services
Using the UI designer Table 6.1 JBuilder s visual design tools Design tools Description UI designer Provides a surface for placing and editing panels and other UI components. To access the UI designer for an open file, select the Design tab at the bottom of the content pane. Component palette Contains visual and nonvisual Java components. Components on the palette vary by JBuilder edition. Component tree Displays a structured view of all the components in your source file and their relationships. This is shown in the structure pane at the lower left of the AppBrowser. Inspector Used to inspect and set the values of component properties and to attach methods to component events. Changes made in the Inspector are reflected visually in your design. Menu designer Used to design menus on the design surface. To invoke it while in the UI designer, double-click a JMenuBar or JPopupMenu component in the component tree, or select the component and press Enter. Available in JBuilder Column designer Allows you to work visually with data set components. To Professional and Enterprise invoke it, double-click a data set. For more information, see Chapter 16, Building an application and Chapter 19, Building a Java text editor. You can also see the online tutorial Creating a UI with nested layouts. For more information, see Designing a user interface in Building Applications with JBuilder. Using the UI designer JBuilder provides tools for visually designing and programming Java classes, allowing you to produce new compound or complex components. To use the visual design tools, a file must meet the following requirements: It must be a Java file (excluding Inner and Anonymous classes). It must be free from syntax errors. It must contain a class whose name matches the file name. Note The class cannot be an Inner class or an Anonymous class. The UI designer is used to manipulate JavaBeans that extend java.awt.Container. For example, the JavaBean can extend any of the following classes: JFrame JPanel JDialog JApplet Note These requirements are all met when you create files with the Application wizard or the Applet wizard. 6-2 Learning Java with JBuilder
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services
Chapter 6 Building a user interface Using JBuilder s visual design tools, you can quickly and easily create a user interface (UI) for a Java application or applet. You construct the UI using a palette that contains components such as buttons, text areas, lists, dialogs, and menus. Then you set the values of the component properties and attach event-handler code to the component events, telling the program how to respond to UI events. Figure 6.1 The AppBrowser and the UI designer Building a user interface 6-1
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services
5-16 Learning Java with JBuilder
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services