B4J Question How to translate "Dim rectGrid as Rect" to B4J?

positrom2

Active Member
Licensed User
Longtime User
I am trying to translate KitCarlson's chart recorder to B4J. Many objects have the same name as in B4A. But some not:
B4X:
'B4A
    Dim btnStart As Button
    Dim pnlChart As Panel
    Dim cvsGraph As Canvas
    Dim rectGrid As Rect
    Dim SrcRec, DestRec, PltRec As Rect
....

    rectGrid.Initialize(GridX0, GridY0, GridX1, GridY1)   ' initialize rectangle
Substituting Panel by Pane might be obvious (have to see the final result...) but what to do for Rect?
Also,
how to translate rectGrid.Initialize(...)?
Thanks for help. If finally successful, I will post the B4J code:)
 

BPak

Active Member
Licensed User
Longtime User
Type rect(left As Int, top As Int, right As Int, bottom As Int)

Dim r As rect
r.left = 12
 
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
Thanks BPak, that works, but translating that chart recorder (B4A) to B4J turns out to be beyond my capabilities. The laguages though similar differ in too many details. I gave up and programmed the chart recorder from scratch using the basics. It's gone little slow since I redraw all the points in the chart each time a new value arrives. So I will try to convert the more elegant scrolling method used in the KitCarlson's example:
B4X:
cvsGraph.DrawBitmap(cvsGraph.Bitmap,SrcRec,DestRec) 'B4A: copy scroll grid and plots
Unfortunately, in B4J this won't work. Is there any suggestion how to convert?
 
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
B4X:
Sub grid
For i=-1000 To 1000 Step 200
y1 = Round(i * c1 + c2)
      cvs.DrawLine(0,y1,cvs.Width,y1,    fx.Colors.red,1)
Next
image1=cvs.Snapshot
cvs.DrawImage2(image1,0,0,cvs.Width,cvs.Height,0,0,cvs.Width,cvs.Height) 
End Sub
This code works without error. However, using the line cvs.Drawimage2(...) in another sub I get the error "object should first be initialized (image)". But Initialize then wants to load an image from file what might not be needed.
I had used Dim, Public, Private as image1, but no difference.
Why can't I use image1=cvs.Snapshot in a different sub?
 
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
Is this the code that fails?
No, sorry, that code runs. But strange, after having done a cold-start of the PC after dinner I can move the lines
B4X:
image1=cvs.Snapshot
cvs.DrawImage2(cvs.snapshot,0,0,cvs.Width,cvs.Height,-1,0,cvs.Width,cvs.Height)
anywhere in the program without getting that error. The error mentioned above was not a compiler error but happend when the program was started -in debug and release modes.
Thank you for your help.
 
Upvote 0
Top