I created a simple UI with Glade. There's a built in "Gnome App" widget, which contains the beginnings as a main application window - menu bar, status bar and an area to place more widgets.
With the glade file in hand I created 1 class and 1 script. The class is the backing for glade - it loads the glade file and handles it's events. I also added a show method to make the app display. At the moment, it only handles 2 events - the event from the File -> Close menu item and the delete-event, which is sent when you click on the X button on the right hand corner.
import org.gnu.glade.LibGlade;
import org.gnu.gtk.Gtk;
import org.gnu.gtk.event.GtkEvent;
public class TestApp {
private static final String GLADE_FILE = "TestApp.glade"
private LibGlade libglade;
public TestApp() {
libglade = new LibGlade(GLADE_FILE, this);
}
public void show() {
libglade.getWidget("gnomeapp1").show()
}
private quitApp(int res) {
Gtk.mainQuit()
System.exit(res)
}
public on_FileQuit(GtkEvent event) {
this.quitApp(0)
}
public on_DeleteEvent(GtkEvent event) {
this.quitApp(0)
}
}
The script is a couple lines, enough to initialize Gnome (and, by extenision GTK), create an instance of the main application class, cause the main window to be shown and then enter the Gtk main loop
import org.gnu.gtk.Gtk;
import org.gnu.gnome.Program;
Program.initGnomeUI("TestApp", "0.1", args);
TestApp gui = new TestApp()
gui.show()
Gtk.main()
No comments:
Post a Comment