oracledba.help
QuickStarts

Basic for Java (B4J)

<- QuickStarts

Overview

B4J is a 100% free development tool that generates desktop, server and web applications. The compiled apps can run on Windows, Mac, Linux and ARM boards (such as Raspberry Pi). One huge benefit of the applications you create with B4J is that your applications can run on Android and iOS devices too.

Useful Links

Prerequisites

  1. Download Java 7 JDK.
  2. Download JavaFX Scene Builder 2.0.
  3. Download B4J Full Version.
  4. Download the latest jdbc driver (ojdbc7.jar).
  5. Create folder for your apps (C:\app\b4j).
  6. Create folder for library files (C:\app\b4j\libs).

Installation

1. Run installers for Java JDK v7 and JavaFX Scene Builder 2.0.

Use the default values when installing both of these.

2. Install and configure B4J.

  1. Run B4J.exe installer.
  2. Use default destination location.
  3. Select Install
  4. Set java path in B4J.
    • Once installed launch B4J.
    • Tools -> Paths Configuration -> Set path to javac.exe

Test

Test to ensure everything thus far is configured OK.

  1. Create a path for a test app.
    Ex: C:\app\b4j\test1
  2. B4J loads with a minimal app. Press the blue Run button and save project to new folder.
    Ex: C:\app\b4j\test1\test1.b4j
  3. Program will compile.
  4. Once done it launches an application with a generic window.

Configure and Test Oracle

  1. Copy the jdbc driver (ojdbc7.jar) to your library folder (C:\app\b4j\libs).
  2. Set additional libraries folder in B4J. Tools -> Paths Configuration -> Additional libraries: C:\app\b4j\libs
  3. Create small test app and folder (C:\app\b4j\oratest).
  4. On the Libs tab (bottom-right) enable: [x] jSQL

Source Code for oratest:

#Region  Project Attributes 	
   #MainFormWidth: 600	
   #MainFormHeight: 400	
   #AdditionalJar: ojdbc7.jar	
End Region

Sub Process_Globals	
   Private fx As JFX	
   Private MainForm As Form	
   Dim conn As SQL
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   conn.InitializeAsync("conn", "oracle.jdbc.driver.OracleDriver", _  
        "jdbc:oracle:thin:@//localhost:1521/MyDB","SCOTT","tiger")
   MainForm.Show
End Sub

Sub conn_Ready (Success As Boolean)
   If Success = False Then
      Log(LastException)
      Return
   End If

   Dim rs As ResultSet = conn.ExecQuery("SELECT sysdate FROM dual")
   Do While rs.NextRow		
      Log(rs.GetString2(0))	
   Loop
   rs.Close
End Sub

Scene Builder Essentials

The terms Form and AnchorPane are synonymous for these instructions.

Stretch Control to Fill Entire Form (TabPane example)

  • Set Form starting width.
    1. Select the Form image.
    2. From right menu select Layout.
    3. Pref Width (ex: 800)
    4. Pref Height (ex: 400)
  • Select TabPane (click the top of control to select entire control)
    1. From right menu select Layout.
    2. For the Anchor Pane Constraints set the left, top, bottom and right to 0 (zero).
      Control resizes to Form when they are all zero.

Form Resize and Controls

Anchor Pane Constraints can be used to keep a controls relative position on a form.
For instance for a button to stay in the same spot on the top-right of a form simply
set the corresponding properties (top and right).

For a TableView it will require some code too for the cells to resize proportionally.

Sub TableView1_Resize (Width As Double, Height As Double)
   'For this code to the cells resizeable from the layout set
   'the AnchorPane Constraints (Top, Right, Bottom, Left).
   For i = 0 To TableView1.ColumnsCount - 1
      TableView1.SetColumnWidth(i, (Width - 10dip)/ TableView1.ColumnsCount)
   Next
End Sub

TabPane

  • Setting Background Color of Tabs (Ex: to #eeeeee)
    1. Drag a TabPane to your form (or Double-Click on TabPane).
    2. Select Tab.
    3. Select tab body (properties changes accordingly).
    4. Left-click the Style text box to bring up list.
    5. Set Style type value: -fx-background-color
    6. Enter Style color value: #eeeeee
    7. Repeat for each tab.

<- QuickStarts