You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

theuserbl

Intermediate

  • "theuserbl" started this thread

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

1

Sunday, June 20th 2010, 5:34pm

Fun with BeanShell + JabacoFramework

Hi!

Today we want to work interactive with the Jabaco-Framework.

At first, download the latest BeanShell at http://www.beanshell.org/bsh-2.0b5.jar
Then unzip bsh-2.0b5.jar and unzip Jabaco.jar and create from this two jars a new Jar, which have all files inside (be sure, that the META-INF file comes from bsh-2.0b5.jar and not from Jabaco.jar.

If it is to difficult for you, you can download at http://www.file-upload.net/download-2612…jabaco.jar.html a file created by me. It includes all of bsh-2.0b5.jar and all of the latest Jabaco-SVN framework version.

Now start the BeanShell with
java -jar bsh-2.0b5jabaco.jar

It comes a splash screen with the text "BeanShell 2.0" and a Bean with a face.
If shortly after that, don't opend the BeanShell Desktop window, then kill the process with the TaskManager or so and start it again.
Sadly BeanShell have a bug, that it starts not every time correct, so you have to try it again and again, until the "BeanShell Desktop" opens.

On the "BeanShell Desktop" there is a "Bsh Workspace" with a shell-prompt.

First write in there

Source code

1
2
bsh % import VB.*;
bsh % import VBA.*;

to using the Jabaco-classes easily.

Now write

Source code

1
2
3
4
5
6
bsh % f = new JFrame("My Window");
bsh % p = new JPanel();
bsh % p.setLayout(null);
bsh % f.add(p);
bsh % f.setSize(400,300);
bsh % f.setVisible(true);


It opens now a window with the title "My Window", which is empty.
Don't close it and don't resize it. And be sure, that you can everytime completly seeing it.
What you now typing in the BeanShell is interactive, so you can it direct seen in the window "My Window".

The part which I have now written, is the only Swing part. Now we want to write something with Javaco-classes:

Creating two Buttons:

Source code

1
2
3
4
5
bsh % b1 = new CommandButton();
bsh % b2 = new CommandButton();
bsh % p.add(b1);
bsh % p.add(b2);
bsh % f.setVisible(true);

And giving the first one some properties, so we can see it:

Source code

1
2
3
4
5
bsh % b1.$Visible(true);
bsh % b1.$Top(50);
bsh % b1.$Left(30);
bsh % b1.$Height(50);
bsh % b1.$Width(130);

Now we see the button. Lets giving it a text like on the Jabaco-IDE at standard:

Source code

1
bsh % b1.$Caption("Command1");


And now doing similar with the second button:

Source code

1
2
3
4
5
6
bsh % b2.$Visible(true);
bsh % b2.$Top(70);
bsh % b2.$Left(200);
bsh % b2.$Width(100);
bsh % b2.$Height(40);
bsh % b2.$Caption("Command2");


With the Jabaco-framework it is easily to moving widgets/components around.
Lets moving the second button rotatly down:

Source code

1
bsh % for (int i=0;i<=1000;i++) { b2.$Top(70+(i%100)); Thread.sleep(2); }


This was really easy, right?


Now lets insert a different widget. A Jabaco slider:

Source code

1
2
bsh % s = new Slider();
bsh % p.add(s);


... and giving it a size and position, so that we can see it:


Source code

1
2
3
4
5
bsh % s.$Visible(true);
bsh % s.$Top(10);
bsh % s.$Height(30);
bsh % s.$Left(20);
bsh % s.$Width(300);


Give it a value:

Source code

1
bsh % s.$Value(70);


Now change the slider in the "My Window" window, so that it have a different value.
But what value is the current one?

Let us first try out to open a Messagebox with a text:

Source code

1
bsh % Interaction.MsgBox("MsgBox Test");


Ok, it works. Now let us see the value of the slider:

Source code

1
bsh % Interaction.MsgBox(String.valueOf(s.$Value()));



Now let us try out something different. Something you can not direct try out in Jabaco and its current IDE:

Source code

1
2
3
bsh % l = new Line();
bsh % p.add(l);
bsh % l.$Visible(true);


Source code

1
bsh % l.$Top(40);


Umpf.. There comes an error message:

Quoted

// Error: EvalError: Error in method invocation: Method $Top( int ) not found in class'VB.Line' : at Line: 1 : in file: <unknown file> : l .$Top ( 40 )

Now clinking with the right mouse key on the BeanShell-Desktop and cicking in the upcomming menu on "New Class Bwowser".
(Btw: The Class Browser of BeanShell is the best I have ever seen. If you know a better one, let me hear about it)

Clinking now in the "Packages" section on "VB".
And then in the "Classes" section on "Line".

Now we can see, that "Line" have no Method called "$Top".
Instead it have methods called "$X1()", "$X1(long)", "$X2()", "$X2(long)", "$Y1()", "$Y1(long)", "$Y2()", "$Y2(long)".
The methods with "long" sets a value. That one with empty brackets are asking about the current value.
Similar we have already done with the slider. "s.$Value(70)" have set the value and with "Interaction.MsgBox(String.valueOf(s.$Value()))" we have put out the current value.

Now trying out the Line class:

Source code

1
2
3
4
bsh % l.$X1(40);
bsh % l.$X2(240);
bsh % l.$Y1(150);
bsh % l.$Y2(80);


If you play around with "Line" you will see, that it is still a buggy implementation. But you can already try it out, what is with the current Jabaco-IDE not possible.


What we have now done, is also something, what graphical designer of IDEs doing. If you change the "Caption" property of a button to "new Text", it is the same like if you write here "b1.$Caption("new Text");"

The difference between a normal designer GUI is, that the designer GUI creates over every widget an additional widget, which is transparent and catches all events.

Greatings
theuserbl

Rate this thread
WoltLab Burning Board