B4J - Basic for Java

203 views
Skip to first unread message

Jerry Rutherford

unread,
Aug 2, 2015, 10:34:08 PM8/2/15
to The Robot Group Mailing List, Austin Hacker Space New
When it comes to programming, I know a little, but many times I feel like a neanderthal. So when i say that a development package is easy to use... it really is.

JAVA is an interesting concept... each machine has within it a "Virtual Machine"... in other words, if you have an Apple, Widows, Android, or Linux ... they all have different ways of doing graphics, making sounds, etc. So what developers have done is to program a version of JAVA for each machine type... and when installed... it acts like a translator or interface card.

If you say to make the screen green... it will automatically pass along the instructions to perform the task... independent from whatever machine it is running on. I downloaded the JAVA programming interface, the Eclipse UI, and a bunch of other stuff... I tinkered with it for about a week and was able to make a blue screen with "Jerry was here".

But now they developed Basic for Android... and the man who invented it figured out that he was 95% of the way to creating the ability to use his front-end to convert to JAVA. So he wrote B4J which compiles to JAVA... and in theory will work on whatever platform you happen to have. Then... he decided to release it for FREE. And I don't mean a crippled version or one with advertising... I mean.... FREE. No strings attached.

So I decided to try it out... trust me... if I can get it to work... anyone can. And I got it to compile perfectly within 15 minutes... so I'm excited.

You can get it here: http://www.b4x.com/b4j.html

The first time I opened the designer, it asked me to install DOT NET version 4.5.2 which isn't a big deal... I got it from here...
https://www.microsoft.com/en-us/download/details.aspx?id=42643

Once that was done... I created a directory called "B4J Projects" and in there, I created "Testing-1"... then saved my empty project there. I opened the designer, and I added a button, a label, and a canvas. (Place for graphics). Once that was done... I told the designer to generate the items (sets up all the DIM commands for you) and in the case of the button, I also selected a CLICKED event to do something when I clicked a button.

Here is my actual generated code...
---------------------------------------------------------
#Region  Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 400
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private Button1 As Button
    Private Label1 As Label
    Private bclick As Int
    Private Canvas1 As Canvas
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.SetFormStyle("UNIFIED")
    ' MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.RootPane.LoadLayout("MAIN")
    MainForm.Show
    bclick=0
 End Sub

Sub Button1_MouseClicked (EventData As MouseEvent)
If bclick == 0 Then
    Label1.Text = "Hello World! (Now it's official.)"
    bclick = bclick +1
    Else
    Label1.Text = "You did it again. " & bclick & " times!"
    bclick = bclick +1
End If
    If bclick =5 Then Canvas1.DrawCircle(150,100,30,fx.Colors.Gray,True,3)
    If bclick =9 Then Canvas1.DrawCircle(150,100,90,fx.Colors.red,True,3)
    If bclick > 10 Then ExitApplication
End Sub
---------------------------------------------------------

I compiled it and it worked flawlessly. (And other than my one attempt at JAVA 12 years ago... have never programmed this before!)

Then I changed the build type from DEBUG to RELEASE in the drop-down and it created a file in the OBJECTS folder "result.jar" which in theory should be the whole program ready to run.

I put it in a completely different folder... on a whole other drive... and I clicked it... a window opened up, and it ran perfectly. ( Whoo! )

In theory... I could put this file on my Linux machine, iPod, or Android and it would also run just fine. (I'll test that theory.)

If I could do all that in the span of an our or so... I REALLY want to see what some of YOU can do with it. It should have the ability to do TCP/IP and all sorts of stuff... so we should be able to make robotic control interfaces that are not machine dependent. Who knows?

Thoughts? Suggestions?
Jerry






Askjerry... everyone else does.
Visit me online at http://askjerry.info
See my projects, video links, tutorials, and blog today.
http://youtube.com/askjerry https://www.facebook.com/jerryarutherford http://askjerry.info
Reply all
Reply to author
Forward
0 new messages