The Source for Java Technology Collaboration
User: Password:



Bruno Ghisi's Blog

Community: Java Tools Archives


Marging a FX Tetris at JavaOne!

Posted by brunogh on April 27, 2008 at 06:10 PM | Permalink | Comments (11)

Marge (Java Bluetooth Framework) got a mini talk in Community Corner. It will be on Wednesday at 3:30 pm. If are you interested in Bluetooth, JSR 82 (Java Apis for Bluetooth) and Marge, do not miss that! We have integrated a Bluetooth mobile controller for a nice James Weaver's compiled JavaFX Script tetris game! Thanks, Jim!

Here is a preview (updated):

The old video is at http://www.youtube.com/v/ZvVx6RGjCjM

It will be easy to find Marge:

margeinthebackpack.jpg

Here is the last tip, keep an eye on the Mobile and Embedded Wiki page for JavaOne!

I am very excited to meet new people! See you in San Francisco!

Bruno Ghisi



Building a Java ME Bluetooth chat in 12 minutes...

Posted by brunogh on April 02, 2008 at 08:05 PM | Permalink | Comments (0)

As it was announced before, Marge 0.5 is out. In this post, I am going to demonstrate an interesting new feature called AutoConnect. AutoConnect is indeed to automatically connect Bluetooth devices. It has some limitations due to some bad implementations and has some scenarios that maybe it is not the best option, but still very interesting and is definitely awesome to make something with a few lines of code! For more information about the new release and this feature, please check http://wiki.java.net/bin/view/Mobileandembedded/HowTo05.

So, nothing better than show a video... [sometimes I think I should have done cinema :) ]... Anyway, if you have not seen any Marge videos yet, try "Project Marge Interview", "My laptop is detecting my presence" and "Giant Blue Pong (my Bluetooth Atari)". Too much talk, take a look at the new "Building a Java ME Bluetooth chat in 12 minutes..." too. Could you not understand what happened in Netbeans code editor? Neither do I!!! It is better to download the full video (30MB). Hope you enjoy!

marduke.png

If you want more about Marge, go to http://marge.dev.java.net. If you want to help, please send an email to owner@marge.dev.java.net. We would love to hear suggestions and have you in our team!

Go ahead! Marge your Bluetooth app!



My First FX Bluetooth App

Posted by brunogh on September 11, 2007 at 07:21 PM | Permalink | Comments (16)

Hey! Today I felt a desire to create something with JavaFX Script and Bluetooth. If you are not familiar with JavaFX, JavaFX Script and so on, take a look in a new and very good Joshua Marinacci's post about it.

I have created an application that allows you to inquiry for devices that are with Bluetooth turned on. It is pretty simple in terms of UI (user interface) and functionality, but the goal here is to show a little of JavaFX Script working with Java.

Here is what you need in this tutorial:

Insert the Bluetooth USB Adpater in your computer, start Netbeans and create a JavaFX project (File->New Project... and select JavaFX and then JavaFX Application), add the two jars in the project classpath and paste the following BTInquiryFX.fx code (note in the code that Marge is used just to start an inquiry - passing an InquiryListener - and to cancel it).

BTInquiryFX.fx


import javafx.ui.*;
import java.lang.*;

import javax.bluetooth.RemoteDevice;
import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;

import net.java.dev.marge.inquiry.DeviceDiscoverer;
import net.java.dev.marge.inquiry.InquiryListener;

    class Model {
        attribute inquiryListener: InquiryListener;
        attribute foundDevices : RemoteDevice[];
        attribute inquiryBtnEnabled : Boolean;
        attribute cancelBtnEnabled : Boolean;
    }

    var model = Model {
        var: self
        inquiryBtnEnabled : true
        cancelBtnEnabled : false
        inquiryListener : new InquiryListener() {
                    operation deviceDiscovered(device: RemoteDevice, deviceClass: DeviceClass) {
                        insert device as last into self.foundDevices; 
                    }

                    operation inquiryCompleted(devices: RemoteDevice[]) {
                        self.inquiryBtnEnabled = true;
                        self.cancelBtnEnabled = false;
                    }

                    operation inquiryError() {
                        self.foundDevices = null;
                        MessageDialog {
                            title: "Error"
                            message: "Inquiry Error"
                            visible: true
                        }
                        self.inquiryBtnEnabled = true;
                        self.cancelBtnEnabled = false;
                    }
            }
    };

    Frame {
            title: "BTInquiryFX"
            width: 400
            height: 200
            resizable: false
            content: BorderPanel {
                top: Label {
                    text: "Found Devices:"
                    }
                center: ListBox {
                     cells: bind foreach (device in model.foundDevices)
                        ListCell {
                                text: "{device.getFriendlyName(false)} - {device.getBluetoothAddress()}"
                        }
                }
                bottom: FlowPanel {
                    content:
                        [Button {
                             text: "Inquiry"
                             enabled : bind model.inquiryBtnEnabled
                             action: operation() {
                                DeviceDiscoverer.getInstance().startInquiry(DiscoveryAgent.GIAC, model.inquiryListener);
                                model.foundDevices = null;
                                model.inquiryBtnEnabled = false;
                                model.cancelBtnEnabled = true;
                             }
                        }, Button {
                             text: "Cancel"
                             enabled : bind model.cancelBtnEnabled
                             action: operation() {
                                DeviceDiscoverer.getInstance().cancelInquiry();
                                model.inquiryBtnEnabled = true;
                                model.cancelBtnEnabled = false;
                             }
                        }]
                }
            }
            visible: true
        };

Screenshots

Then... run it! Here is what we got...

btinquiryfx1.png

and after the inquiry is completed...

btinquiryfx2.png

my mobile was found! My mobile runs Java too!!! ;)


PS: Learn more about JavaFX Script in Project OpenJFX. You can find good tutorials, fresh releases, plugins for Eclipse and Netbeans, a lot of good support, demo applications... Try it now!


Cheers,

Bruno Ghisi

JSR 82 is not only for mobiles!

Posted by brunogh on September 04, 2007 at 04:59 AM | Permalink | Comments (13)

How could you create Java SE Bluetooth applications, since JSR 82 (Java Apis for Bluetooth) was made thinking in Java ME? In this entry, I am going to explain some aspects around it and also give some tips in order to you start doing Bluetooth desktop applications. In addition, we are going to talk a little about the GCF (Generic Connection Framework).

JSR 82 (Java Apis for Bluetooth) uses GCF, which is an extensible framework intended to support all kind of connections. GCF was defined in CLDC (Connected Limited Device Configuration) 1.0 and CLDC is a usual Java ME configuration for mobile phones. CLDC does not specify the actual supported network protocols or mandate implementations of any specific networking protocols, they are made at the profile level, such as, for example, MIDP (Mobile Information Device Profile). Read this C. Enrique Ortiz's article in order to get more information about GCF.

GCF does not only works in CLDC, it can run in CDC (Connected Device Configuration) - differing from CLDC, CDC requires two protocols to be implemented: File access and Datagram capability, and profiles will extend others - and it is also provided to the Java SE platform as an optional package with JSR 197 (Generic Connection Framework Optional Package for the J2SETM Platform), which is derivated from CLDC 1.1 and mandates a minimum of protocols: Socket, HTTP, File and Datagram. Having GCF in Java SE means that you can use JSR 82 to make compliant desktop applications, you will just need a JSR 82 implementation for that in your classpath. There is a lot of them for different OS (operating system) that runs in different Bluetooth stacks, but I recommend you to try some open source ones:

  • Bluecove, which runs over Windows (WIDCOMM, BlueSoleil and Microsoft Bluetooth stack found in Windows XP SP2 and newer) and [updated] at the moment it is not JSR-82 certified implementation (has not passed in all the TCK tests, take a look in Vlad's comment in this entry for more explanation) [updated], but they also have plans to extend it to Linux. Take a look in a cool interview about this project here.
  • Avetana, which has a open source version that runs over Linux (BlueZ stack). Lucas Torri used Avetana on the experiments that he have posted.

So, after you got a JSR 82 implementation, you will need a USB Bluetooth dongle - if your desktop does not have a Bluetooth hardware support, because a lot of notebooks are coming with it - and then you can start coding and creating applications that use your desktop, such as, for example, something to communicate with your mobile, remote controllers and so on. Also, Project Marge has a framework on the top of JSR 82 that facilitates a lot of Bluetooth stuff and it is compatible with Java SE. My final advice is that Rococo has a 100% Java free simulator (for non commercial use), called Impronto Simulator. You can use it to test your Java SE Bluetooth code in a simulated environment, it is quite cool before deploying. Take a try doing something and sent me your feedback! ;)

Have a great week!

Bruno Ghisi





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds