B4J Tutorial DotMatrix

It is based on this posting. Copy the attached Jar to your B4J library folder.
Sample project attached
See how the chars scroll across the DotMatrix - the code (via a timer) will repeat the scroll of the text
Seems to think that you need to use at least Java 17. I have done this using Java 19.

1.png


[CODE lang="b4x" title="B4J code using JavaObject"]#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region

#AdditionalJar: dotmatrix-17.0.0

Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Dim matrix As JavaObject
Dim width, height As Double
Dim cols, row As Int
Dim dm As JavaObject
Dim dmb As JavaObject
Dim mf As JavaObject
Dim x, offset As Int
Dim txt As String

Dim textLengthInPixel As Int
Dim textlength As Int

Dim t As Timer
End Sub

Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show

t.Initialize("t", 50)

txt = "Hello Johan, Belinda, Chris, Stertjie, Peanut, Nunu (Buffel), and Kiki (uiltjie ogies)"
textLengthInPixel = txt.Length * 8
matrix.InitializeNewInstance("eu.hansolo.fx.dotmatrix.DotMatrix", Null)

width = 500
height = 50

cols = 128
row = 13

'ROUND, SQUARE, ROUNDED_RECT
dm.InitializeStatic("eu.hansolo.fx.dotmatrix.DotMatrix.DotShape")

dmb.InitializeStatic("eu.hansolo.fx.dotmatrix.DotMatrixBuilder")

'MatrixFont5x7, MatrixFont8x11, MatrixFont8x8
mf.InitializeStatic("eu.hansolo.fx.dotmatrix.MatrixFont8x8")

matrix = dmb.RunMethodJO("create", Null) _
.RunMethodJO("prefSize", Array(width, height)) _
.RunMethodJo("colsAndRows", Array(cols, row)) _
.RunMethodJO("activeColor", Array(fx.Colors.RGB(255, 55, 0))) _
.RunMethodJO("dotShape", Array(dm.GetField("ROUND"))) _
.RunMethodJO("matrixFont", Array(mf.GetField("INSTANCE"))) _
.RunMethodJO("useSpacer", Array(False)) _
.RunMethod("build", Null)

x = matrix.RunMethod("getCols", Null) + 7

MainForm.RootPane.AddNode(matrix, 2dip, 2dip, 550dip, 300dip)



t.Enabled = True

End Sub

Sub t_tick
If x < -1 * textLengthInPixel Then
x = matrix.RunMethod("getCols", Null) + 7
End If
offset = 3 'how far from the top of the matrix do we start
textlength = txt.Length
textLengthInPixel = textlength * 8

For i = 0 To txt.Length - 1
matrix.RunMethod("setCharAt", Array(txt.CharAt(i), x + i * 8, offset, IIf(i Mod 2 = 0, matrix.runMethod("convertToInt", Array(fx.Colors.Red)), matrix.runMethod("convertToInt", Array(fx.Colors.Blue)))))
Next
x = x - 1

End Sub [/CODE]

I am leaving any further changes to this sample up to you. Study the attached JAR and classes within by making use of a suitable JAR viewer such as "jd-gui"
 

Attachments

Last edited:
Hey, you ve remembered me old days of my invoice app (vb6 created and using it still here - time to replace it with b4x apps)

1757322800702.png


How can i change back dot-matrix colors ?

and how i can use unicode fonts to it ?
(not showing greek)

Thanks in advance!

edit:
ps: Beautiful Work as always @Johan Schoeman
 
Is it possible to change this your java object to b4a compatible? I tried using XUI equivalent instead to replace all FX related like in color: fx.Colors.RGB(255, 55, 0) until there is no more error indicator in the code. The jar was declared correctly in the main and copied into additional folder. After my correction, the code compiled successfully, but didn't run with no error. When I got tired, I packed the code somewhere to do other things.

Can it be adapted to b4a or is there anybody that has the one that is b4a or b4x compatible?
 
Is it possible to change this your java object to b4a compatible? I tried using XUI equivalent instead to replace all FX related like in color: fx.Colors.RGB(255, 55, 0) until there is no more error indicator in the code. The jar was declared correctly in the main and copied into additional folder. After my correction, the code compiled successfully, but didn't run with no error. When I got tired, I packed the code somewhere to do other things.

Can it be adapted to b4a or is there anybody that has the one that is b4a or b4x compatible?
It will not work in B4A it depends on JavaFX classes.
 
  • Like
Reactions: omo
It will not work in B4A it depends on JavaFX classes.
Ok, thank you; Noted! I sensed so initially, but one bypass post I saw using XUI instead made me to try that trick, and compiled and ran on phone further confused me. I was expecting it would give error relating to b4j core. Now, I know, thank you. I will look for planB
 
Back
Top