Showing posts with label java-gnome. Show all posts
Showing posts with label java-gnome. Show all posts

Sunday, December 22, 2013

Example of programming with java-gnome

Once installed libjava-gnome-java, we can prepare our "Hello World" using java-gnome. Basically it have the same function as "GTK+ exercise: GtkBox - A container box", a basic GTK+ Window with 3 Labels.

helloGnome
helloGnome
Edit helloGnome.java
import org.gnome.gtk.Gtk;
import org.gnome.gtk.Window;
import org.gnome.gtk.Widget;
import org.gnome.gdk.Event;
import org.gnome.gtk.Label;
import org.gnome.gtk.HBox;

public class helloGnome
{
    public static void main(String[] args) {
        final Window window;
        final HBox hBox;
        final Label label1, label2, label3;

        Gtk.init(args);

        window = new Window();
        window.setTitle("Hello Raspberry Pi - java-gnome exercise");
        window.connect(new Window.DeleteEvent() {
            public boolean onDeleteEvent(Widget source, Event event) {
                Gtk.mainQuit();
                return false;
            }
        });

        label1 = new Label("Label 1");
        label2 = new Label("Label 2");
        label3 = new Label("Label 3");

        hBox = new HBox(false, 3);
        hBox.add(label1);
        hBox.add(label2);
        hBox.add(label3);

        window.add(hBox);
        window.showAll();

        Gtk.main();
    }
}


Compile it with the command:
$ javac -classpath /usr/share/java/gtk-4.1.jar helloGnome.java

and run it:
$ java -classpath /usr/share/java/gtk-4.1.jar:. helloGnome

Install java-gnome on Raspberry Pi

java-gnome, currently 4.1, are the Java bindings for GTK and GNOME. Featuring a robust engineering design, completely generated internals, a lovingly crafted layer presenting the public API, and steadily increasing coverage of the underlying libraries.

You can use java-gnome to develop sophisticated user interfaces for Linux applications so that they richly integrate with the GNOME Desktop while leveraging the power of the Java language and your expertise with it.

To install java-gnome, enter the command:
$ sudo apt-get install libjava-gnome-java

Please notice that the file gtk-4.1.jar will be installed in /usr/share/java/, you will need it when compile and run the java using java-gnome.

/usr/share/java/gtk-4.1
/usr/share/java/gtk-4.1
Next:
- Example of programming with java-gnome