B4J - Bouncing Smiley

Erel

B4X founder
Staff member
Licensed User
Longtime User
SS-2013-11-05_17.58.36.png


Please try the attached B4J app. It depends on Java 7 (update 6+).

If Java is installed then you should just double click on it and it should run.

It should work on Windows, Mac or Linux.

The code:
B4X:
Sub Process_Globals
   Private MainForm As Form
   Private fx As JFX
   Dim cvs As Canvas
   Private smiley As Image
   Private Timer1 As Timer
   Dim deg, x, y, vx = 10dip, vy = 10dip As Double
   Dim size As Double = 40dip
End Sub

Sub AppStart (Form1 As Form)
   MainForm = Form1
   smiley = fx.LoadImage(File.DirAssets, "smiley.gif")
   MainForm.Width = 500dip
   MainForm.Height = 700dip
   MainForm.MaxHeight = 1000dip
   MainForm.MaxWidth = 1000dip
   MainForm.Title = "Smiley"
   cvs.Initialize("cvs")
   MainForm.RootPane.AddNode(cvs, 0, 0, MainForm.Width, MainForm.Height)
   MainForm.Icons.Add(smiley)
   MainForm.Show
   x = MainForm.Width / 2
   y = MainForm.Height / 2
   Timer1.Initialize("Timer1", 15)
   Timer1.Enabled = True
End Sub

Sub MainForm_Resize (Width As Double, Height As Double)
   cvs.Width = Width
   cvs.Height = Height
End Sub

Sub Timer1_Tick
   cvs.ClearRect(x, y, 50dip, 50dip)
   If x + size > cvs.Width Then
     vx = -Abs(vx)
   Else If x < 0 Then
     vx = Abs(vx)
   End If
   If y + size > cvs.Height Then
     vy = -Abs(vy)
   Else If y < 0 Then
     vy = Abs(vy)
   End If
   x = x + vx
   y = y + vy
   deg = deg + 1
   cvs.DrawImageRotated(smiley, x, y, size, size, deg)
End Sub

Does it work for you???
 

Attachments

  • Smiley.jar
    183.4 KB · Views: 329

Woinowski

Active Member
Licensed User
Longtime User
Yes it does, Win 7.

This is so cool. Will B4J work with code originally programmed for B4A?

Jens
 

barx

Well-Known Member
Licensed User
Longtime User
Yes it does, Win 7.

This is so cool. Will B4J work with code originally programmed for B4A?

Jens

It was previously mentioned that any code that doesn't call /reference android specific stuff will work ;)
 

barx

Well-Known Member
Licensed User
Longtime User
Works here too, even carries on if you re-size the window. Max'ing the window doesn't fill the screen though, but hey. This is awesome.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Max'ing the window doesn't fill the screen though
The code limits the form to 1000 x 1000 (see Sub AppStart). The smiley was not moving smoothly on large screens so I limited it, seems like the canvas object is less efficient with large dimensions.

Programming with B4J will be simpler than programming with B4A because the Android environment is much more complicated.

The UI is based on JavaFX. It is completely different than Android UI.
 

barx

Well-Known Member
Licensed User
Longtime User
The code limits the form to 1000 x 1000 (see Sub AppStart). The smiley was not moving smoothly on large screens so I limited it, seems like the canvas object is less efficient with large dimensions.

Programming with B4J will be simpler than programming with B4A because the Android environment is much more complicated.

The UI is based on JavaFX. It is completely different than Android UI.

Indeed you are correct. I got a little giddy, skipped the code reading and jumped to the download.... typical n00b I guess
 

Penguin

Member
Licensed User
Longtime User
Works for me, too.

On Win 7 (64Bit and SP1)

and it works on Ubuntu 12.04 (64bit), too!

Can't wait for B4J to be released :)
 

agraham

Expert
Licensed User
Longtime User
Works on my Windows 7 desktop but the right and bottom edges collision detection seems off. It looks like the canvas size might be the overall size of the window and not the size of the client area of that window.

It also works on Windows 8.1 Surface Pro with the desktop scaled at 150% but the right and bottom detection is even worse, the smiley vanishes off the screen at the bottom!
 

ivanomonti

Expert
Licensed User
Longtime User
Screen Shot 2013-11-05 at 7.34.45 PM.png


Software OS X 10.9 (13A603)
Graphics NVIDIA GeForce 9400M 256 MB
Memory 8 GB 1067 MHz DDR3
Processor 3.06 GHz Intel Core 2 Duo
 

Jim Brown

Active Member
Licensed User
Longtime User
*Edited*

It was not initially running for me - Linux Mint 15 Xfce
First time attempt at running it resulted in "Smiley.jar is not marked as executable". Fixed that with the following:
B4X:
> sudo chmod +x Smiley.jar
Then, when I ran the example I got a JavaFX Launcher popup window saying I need the latest Java runtime.
According an online test though I have the latest version installed - http://apt.ubuntu.com/p/openjdk-7-jre

To get it working I had to use the Oracle Java 7. For any other Mint users see the repository instructions here --> http://www.duinsoft.nl/packages.php?t=en#repo
 
Last edited:
Top