# Writing Applets

Writing applets is very simple. You take some boiler plate code like below, change a couple of things and write the code that implements your widgetry. The hardest part is writing your widgetry - and its completely up to yourself how hard that should be.

# Hello World Applet

As usual, following the pointless tradition of starting with an example of how get 'Hello World' on the screen in some form, here's just about the simplest applet you could write.

    #include <string.h>

    #include <panel-applet.h>
    #include <gtk/gtklabel.h>

    static gboolean
    hello_applet_fill (PanelApplet *applet,
    		   const gchar *iid,
    		   gpointer     data)
    {
            GtkWidget *label;

            if (strcmp (iid, "OAFIID:My_HelloApplet") != 0)
    		return FALSE;

            label = gtk_label_new ("Hello World");
    	gtk_container_add (GTK_CONTAINER (applet), label);

    	gtk_widget_show_all (GTK_WIDGET (applet));

            return TRUE;
    }

    PANEL_APPLET_BONOBO_FACTORY ("OAFIID:My_HelloApplet_Factory",
                                 PANEL_TYPE_APPLET,
                                 "The Hello World Applet",
                                 "0",
                                 hello_applet_fill,
                                 NULL);

The code here is very similar to writing a normal Bonobo control. You define a factory using PANEL_APPLET_BONOBO_FACTORY(), passing it a factory function like hello_applet_fill().

libpanel-applet automatically creates a #PanelApplet object for you, passing this to your factory method. Here, you should fill the applet with your widgets just like a #GtkBin. For example, if you were writing a cdplayer applet you would create a #GtkHBox, pack the hbox with the cdplayer buttons and in turn add the hbox to the applet.