This is a very simple example on how to organize your code as a multipagewith multiple classes, while transpiled it is a SPA.
main:
Sub Process_Globals
Private BANano As BANano 'ignore
' your logical pages
Dim myPage1 As Page1
Dim myPage2 As Page2
End Sub
Sub AppStart (Form1 As Form, Args() As String)
' With this little snippet, the new B4J 9.30 logs with jump are activated
#if Debug
' MUST be literally this line if you want to use the B4J Logs jump to code feature!
Log("BANanoLOGS")
#End if
' some general settings like the name of your PWA
BANano.Initialize("BANano", "BANanoMinimal",DateTime.Now)
BANano.Header.Title="BANano Minimal"
' DateTime.Now is to make sure our app is reloaded on ReBuild
BANano.JAVASCRIPT_NAME = "app" & DateTime.Now & ".js"
' some directives for the Tranpiler
BANano.TranspilerOptions.MergeAllCSSFiles = True
BANano.TranspilerOptions.MergeAllJavascriptFiles = True
BANano.TranspilerOptions.RemoveDeadCode = True
BANano.TranspilerOptions.ShowWarningDeadCode = True
BANano.TranspilerOptions.EnableLiveCodeSwapping = True
' start the actual build
BANano.Build(File.DirApp)
' stop running. We do not need the .jar file running anymore
' in release mode
#if Release
ExitApplication
#End if
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
' HERE STARTS YOUR APP
Sub BANano_Ready()
' initialize your pages
myPage1.Initialize
myPage2.Initialize
' load the first one
myPage1.Load
End Sub
SharedData module:
'Static code module
Sub Process_Globals
Dim CurrentPage As String
Dim Page1TextBox As String
Dim Page2TextBox As String
End Sub
' saving the data on the page you are leaving
Public Sub SavePreviousPage()
Select Case CurrentPage
Case "Page1"
Page1TextBox = Main.MyPage1.SKTextBox1.Text
Case "Page2"
Page2TextBox = Main.MyPage2.SKTextBox1.Text
End Select
End Sub
' loading the data previously saved
public Sub LoadThisPage()
Select Case CurrentPage
Case "Page1"
Main.MyPage1.SKTextBox1.Text = Page1TextBox
Case "Page2"
Main.MyPage2.SKTextBox1.Text = Page2TextBox
End Select
End Sub
Page1 class with its Layout Page1. Note that its SKButton_Click event is raised right here in the class.
Sub Class_Globals
Dim BANano As BANano 'ignore
Public SKButton1 As SKButton
Public SKTextBox1 As SKTextBox
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub
public Sub Load()
SharedData.SavePreviousPage
Dim body As BANanoElement
body.Initialize("body")
body.Empty
body.LoadLayout("Page1")
SharedData.CurrentPage = "Page1"
SharedData.LoadThisPage
End Sub
Private Sub SKButton1_Click (event As BANanoEvent)
Main.myPage2.Load
End Sub
Page2 class (same system)
Sub Class_Globals
Dim BANano As BANano 'ignore
Public SKButton1 As SKButton
Public SKTextBox1 As SKTextBox
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub
public Sub Load()
SharedData.SavePreviousPage
Dim body As BANanoElement
body.Initialize("body")
body.Empty
body.LoadLayout("Page2")
SharedData.CurrentPage = "Page2"
SharedData.LoadThisPage
End Sub
Private Sub SKButton1_Click (event As BANanoEvent)
Main.myPage1.Load
End Sub
I like doing it like this as all is well organized: every page it's own events, layout and logic, all data available in a shared module and main is still uncluthered.
Alwaysbusy