'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
#AdditionalJar: lanterna-3.1.2
Sub Process_Globals
Private Terminal As JavaObject
Private Screen As JavaObject
Private TextGraphics As JavaObject
Private gridlayout As JavaObject
Private pannello As JavaObject
Private form As JavaObject
Private gui As JavaObject
Private tBox1 As JavaObject
Private tBox2 As JavaObject
End Sub
Sub AppStart (Args() As String)
'---------------------------------
' Setup terminal and screen layers
'---------------------------------
Terminal = CreateTerminal
Screen = CreateScreen(Terminal)
Screen.RunMethod("startScreen", Null)
Screen.RunMethod("clear", Null)
TextGraphics = Screen.RunMethod("newTextGraphics", Null)
'--------------------------------
' Create Create panel to hold components
'--------------------------------
gridlayout = CreateGridLayout(2)
pannello = CreatePanel
pannello.RunMethod("setLayoutManager", Array As Object(gridlayout))
Dim lbl1 As JavaObject = CreateLabel("Num.1:")
tBox1 = CreateTextBox(CreateTerminalSize(20, 1))
Dim lbl2 As JavaObject = CreateLabel("Num.2:")
tBox2 = CreateTextBox(CreateTerminalSize(20, 1))
Dim spazio_vuoto As JavaObject = CreateEmptySpace(CreateTerminalSize(0,0))
' Creazione e gestione del primo pulsante
Dim button1 As JavaObject = CreateButton
pannello.RunMethod("addComponent", Array As Object(lbl1))
pannello.RunMethod("addComponent", Array As Object(tBox1))
pannello.RunMethod("addComponent", Array As Object(lbl2))
pannello.RunMethod("addComponent", Array As Object(tBox2))
pannello.RunMethod("addComponent", Array As Object(spazio_vuoto))
pannello.RunMethod("addComponent", Array As Object(button1))
'--------------------------------
' Create window to hold the panel
'--------------------------------
form = CreateBasicWindow'
form.RunMethod("setComponent", Array As Object(pannello))
'SetFullScreenHint(BasicWindow)
'BasicWindow.RunMethod("setHints",Array As Object(WindowHint.GetField("FULL_SCREEN")))
'-------------------------
' Create gui and start gui
'-------------------------
gui = MultiWindowTextGUI(Screen, CreateWindowManager, CreateEmptySpaceTextColor(CreateTextColor("RED"))) 'Colore di sfondo
gui.RunMethod("addWindowAndWait", Array As Object(form))
End Sub
Sub Button1_Event (MethodName As String, Args() As Object)
Log("Button clicked")
' Actions go here
AddTwoNumbers
End Sub
Sub AddTwoNumbers
Dim Txt1 As Object = tBox1.RunMethod("getText", Null)
Dim Txt2 As Object = tBox2.RunMethod("getText", Null)
If IsNumber(Txt1) = False Then
Log("Num1 is invalid!")
Return
End If
If IsNumber(Txt2) = False Then
Log("Num2 is invalid!")
Return
End If
Dim Num1 As Int = Txt1
Dim Num2 As Int = Txt2
Log("Result = " & (Num1 + Num2))
End Sub
Sub CreateTerminal As JavaObject
Dim factory As JavaObject
Return factory.InitializeNewInstance("com.googlecode.lanterna.terminal.DefaultTerminalFactory", Null).RunMethod("createTerminal", Null)
End Sub
Sub CreateScreen(Term As Object) As JavaObject
Dim s As JavaObject
Return s.InitializeNewInstance("com.googlecode.lanterna.screen.TerminalScreen", Array(Term))
End Sub
Sub SetCharacter(Char1 As Char, Column As Int, Row As Int)
TextGraphics.RunMethod("setCharacter", Array(Column, Row, Char1))
End Sub
Public Sub SetString (s As String, Column As Int, Row As Int)
TextGraphics.RunMethod("putString", Array(Column, Row, s))
End Sub
Sub Refresh
Screen.RunMethod("refresh", Null)
End Sub
Sub CreateRunnable (EventName As String) As Object
Dim jo As JavaObject
jo.InitializeNewInstance("java.lang.Object", Null)
Return jo.CreateEvent("java.lang.Runnable", EventName, False)
End Sub
Sub CreateTerminalSize (colonne As Int, righe As Int) As JavaObject
Dim componente As JavaObject
Return componente.InitializeNewInstance("com.googlecode.lanterna.TerminalSize", Array As Object(colonne, righe))
End Sub
Sub CreateLabel(etichetta As String) As JavaObject
Dim componente As JavaObject
Return componente.InitializeNewInstance("com.googlecode.lanterna.gui2.Label", Array As Object(etichetta))
End Sub
Sub CreateTextBox(par_terminal_size As JavaObject) As JavaObject
Dim componente As JavaObject
Return componente.InitializeNewInstance("com.googlecode.lanterna.gui2.TextBox", Array As Object(par_terminal_size))
End Sub
Sub CreateButton As JavaObject
Dim jo As JavaObject
Return jo.InitializeNewInstance("com.googlecode.lanterna.gui2.Button", Array("TEST", CreateRunnable("Button1")))
End Sub
Sub CreateGridLayout(colonne As Int) As JavaObject
Dim gl As JavaObject
Return gl.InitializeNewInstance("com.googlecode.lanterna.gui2.GridLayout", Array As Object(colonne))
End Sub
Sub CreatePanel As JavaObject
Dim pnl As JavaObject
Return pnl.InitializeNewInstance("com.googlecode.lanterna.gui2.Panel", Null)
End Sub
Sub CreateBasicWindow As JavaObject
Dim window As JavaObject
Return window.InitializeNewInstance("com.googlecode.lanterna.gui2.BasicWindow", Null)
End Sub
Sub CreateEmptySpace(par_terminal_size As JavaObject) As JavaObject
Dim componente As JavaObject
Return componente.InitializeNewInstance("com.googlecode.lanterna.gui2.EmptySpace", Array As Object(par_terminal_size))
End Sub
Sub CreateEmptySpaceTextColor(par_text_color As JavaObject) As JavaObject
Dim componente As JavaObject
Return componente.InitializeNewInstance("com.googlecode.lanterna.gui2.EmptySpace", Array As Object(par_text_color))
End Sub
Sub CreateTextColor(color As String) As JavaObject
Dim textColorFactory As JavaObject
textColorFactory.InitializeStatic("com.googlecode.lanterna.TextColor$Factory")
' Use the factory to create a TextColor
Dim tc As JavaObject
tc = textColorFactory.RunMethod("fromString", Array As Object(color))
Return tc
End Sub
Sub WindowHint As JavaObject
Dim wh As JavaObject
Return wh.InitializeStatic("com.googlecode.lanterna.gui2.Window.Hint")
End Sub
Sub MultiWindowTextGUI(scr As Object, windowmanager As Object, bg As Object) As JavaObject
Dim gui As JavaObject
Return gui.InitializeNewInstance("com.googlecode.lanterna.gui2.MultiWindowTextGUI", Array As Object(scr, windowmanager, bg))
End Sub
Sub CreateWindowManager As JavaObject
Dim wm As JavaObject
Return wm.InitializeNewInstance("com.googlecode.lanterna.gui2.DefaultWindowManager", Null)
End Sub