### Sample #3 Clock

Example of a Clock controlled by a timer.
The app runs in fully filled screen.
MainForm Layout
Composed with the B4J Visual Designer using following Views: [Label (Title)]
[Label Title][Button X]
[Label Clock]
[Button Close]
[Label Info]
B4J Code Snippet
``Sub Process_Globals
Private CAPPVERSION As String = "v20180419"
Private CAPPTITLE As String = "B4J HowTo Raspberry Pi Liberica JDK10 - Clock"
Private CAPPINFO As String = $"${CAPPVERSION} by Robert W.B. Linn"$
' Libs
Private fx As JFX
' Views
Private MainForm As Form
Private btnCloseX As Button
Private btnClose As Button
Private lblTitle As Label
Private lblStatus As Label
Private lblClock As Label
' The clock timer updating every second
Private ClockTimer As Timer
Private ClockTimerInterval As Long = 1000
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Main")
MainForm.Show
AppInit
End Sub`
`Sub AppInit
' Labels
lblTitle.Text = CAPPTITLE
lblStatus.Text = $"${CAPPINFO} - Java ${GetSystemProperty("java.version","0.0.0_00")}"$
' Buttons
btnClose.Visible = False
'Set the form to fill the screen with an offset
SetFormFillScreenOffset(MainForm, 0)
' Set the background color of the form to blue
CSSUtils.SetBackgroundColor(MainForm.RootPane, fx.Colors.LightGray)
' Clock - setting a big font size eats up GPU Memory
CSSUtils.SetStyleProperty(lblClock, "-fx-font-size", 255)
' ClockTimer
DateTime.TimeFormat = "HH:mm:ss" ' "HH:mm"
SetClock
ClockTimer.Initialize("ClockTimer", ClockTimerInterval)
ClockTimer.Enabled = True
End Sub`
`Sub AppClose
MainForm.Close
ExitApplication
End Sub`
'Return true to allow the default exceptions handler to handle the uncaught exception.
`Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub`
' Close the app using X Button top right corner
`Sub btnCloseX_Action
AppClose
End Sub`
' Close the app using close button bottom right
`Sub btnClose_Action
AppClose
End Sub`
`Sub ClockTimer_Tick
SetClock
End Sub`
`Private Sub SetClock
lblClock.Text = IsNow
End Sub`
' Returns the actual time in the format set by Datetime.TimeFormat
`Sub IsNow As String
Return DateTime.Time(DateTime.Now)
End Sub`
'Set the form to fill the screen with an offset
`Sub SetFormFillScreenOffset(frm As Form, offset As Int) 'ignore
Dim ps As Screen = fx.PrimaryScreen
frm.WindowLeft = ps.MinX + offset
frm.WindowWidth = ps.MaxX - frm.WindowLeft - offset
frm.WindowTop = ps.MinY + offset
frm.WindowHeight = ps.MaxY - frm.WindowTop - offset
End Sub`
`

Changed: 2018-06-07 09:22, Category: Raspberry Pi UI Liberica, File: T6C287M2164.htm, ID: 2164