EXAMPLES

These files are examples of specific parts of the java-gnome API worked up as
complete Java programs.

Source code, especially Java source code, doesn't always lend itself to being
_read_, certainly not from top to bottom. We have attempted, however, to create
some examples which are non-trivial but nonetheless are still readable.

----
<img src="button/ExamplePressMe.png" class="right"/>
### Button in a Window

* [`ExamplePressMe.java`](button/ExamplePressMe.html)  
It doesn't get any simpler than this. A [Label][] and a [Button][] in a
[Window][], showing how to connect a listener to handle a
[`Button.Clicked`][Button.Clicked] signal from the Button and how to ensure
your application terminates when the Window is [deleted][Window.DeleteEvent].
Incidentally, this is what runs if you type `make demo` in a fresh java-gnome
build.

[Button]: /4.0/doc/api/org/gnome/gtk/Button.html
[Label]: /4.0/doc/api/org/gnome/gtk/Label.html
[Window]: /4.0/doc/api/org/gnome/gtk/Window.html
[Button.Clicked]: /4.0/doc/api/org/gnome/gtk/Button.Clicked.html
[Window.DeleteEvent]: /4.0/doc/api/org/gnome/gtk/Window.DeleteEvent.html

----
<img src="keyboard/ExampleSnooping.png" class="right"/>
### Handling keystrokes

* [`ExampleSnooping.java`](keyboard/ExampleSnooping.html)  
Handling keyboard input is more complicated than it reasonably ought to be. In
most cases the existing GTK Widgets already do everything that needs doing
(when you type text into an Entry, the text does indeed go into that Entry),
focus handling, etc. However, if you need to intercept a keystroke so you can
do something special, then you need to work with the [Keyval][] and
[ModifierType][] classes in response to the
[`Widget.KeyPressEvent`][Widget.KeyPressEvent] signal. This is how.

[Keyval]: /4.0/doc/api/org/gnome/gdk/Keyval.html
[ModifierType]: /4.0/doc/api/org/gnome/gdk/ModifierType.html
[Widget.KeyPressEvent]: /4.0/doc/api/org/gnome/gtk/Widget.KeyPressEvent.html

<pre style="max-width:600px;">
Pressed: Keyval.ControlLeft, Modifier: ModifierType.NONE 
Pressed: Keyval.c, Modifier: ModifierType.CONTROL_MASK 
</pre>

----
<img src="treeview/ExampleTrailHeads.png" class="right"/>
### TreeView and TreeModel

* [`ExampleTrailHeads.java`](treeview/ExampleTrailHeads.html)  
While not a complete tutorial, we have an example of a small application which
uses a TreeView backed by a ListStore called `ExampleTrailHeads`.  It is
heavily commented and meant to serve as an introduction of the incredibly
powerful yet very complex [TreeView][] / [TreeModel][] system. It should be
read in conjunction with the API documentation for these types. You'll also
want to read about how to setup a [ListStore][] and the explanation of
available column types in [DataColumn][].

[TreeView]: /4.0/doc/api/org/gnome/gtk/TreeView.html
[TreeModel]: /4.0/doc/api/org/gnome/gtk/TreeModel.html
[ListStore]: /4.0/doc/api/org/gnome/gtk/ListStore.html
[DataColumn]: /4.0/doc/api/org/gnome/gtk/DataColumn.html

----
<img src="textview/ExampleInstantMessenger.png" class="right"/>
### TextView and TextBuffer 

* [`ExampleInstantMessenger.java`](textview/ExampleInstantMessenger.html)  
This is a more involved sample illustrating use of the [TextView][] /
[TextBuffer][] multi-line text display and editing Widget. We set up a
conversation window like you'd see in an instant messaging program, and then
simulate a conversation with someone -- all as a means of demonstrating
setting up the view, doing text insertion into the buffer with [TextIter][] as
well as more advanced features like managing text formatting via [TextTag][]s.
The example is more or less readable from the top, but the program is quite
dynamic and the most fun will be had if you _run_ the thing.

[TextView]: /4.0/doc/api/org/gnome/gtk/TextView.html
[TextBuffer]: /4.0/doc/api/org/gnome/gtk/TextBuffer.html
[TextIter]: /4.0/doc/api/org/gnome/gtk/TextIter.html
[TextTag]: /4.0/doc/api/org/gnome/gtk/TextTag.html

----
<img src="cairo/ExampleCairoDrawingBlends.png" class="right"/>
### Drawing with Cairo 

* [`ExampleDrawingInExposeEvent.java`](cairo/ExampleDrawingInExposeEvent.html)  
FIXME _this needs a better name. For that matter, it needs something more
interesting._  
Using the Cairo Graphics library to draw within a GTK program means following
the idiom shown in this example. This program demonstrates drawing lines,
rectangles, and gradients using a drawing [Context][] as obtained within a
Widget's [Widget.ExposeEvent][] signal handler.

[Context]: /4.0/doc/api/org/freedesktop/cairo/Context.html
[Widget.ExposeEvent]: /4.0/doc/api/org/gnome/gtk/Widget.ExposeEvent.html


<style>
img.right {
	float: right;
	padding-bottom: 10px;
}
hr {
	clear: right;
}
</style>

<!--

  Copyright (c) 2008 Operational Dynamics Consulting Pty Ltd 

  As project documentation, this file forms an integral part of the source
  code of the library it accompanies, and thus is made available to you by the
  authors under the terms of the "GNU General Public Licence, version 2". See
  the LICENCE file for the terms governing usage, copying and redistribution.

  vim: set textwidth=78 nowrap:

-->
