DOC PREVIEW
Princeton COS 333 - Graphical user interfaces

This preview shows page 1-2-19-20 out of 20 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1Graphical user interfaces• examples– X Window system– Java Swing–Visual Basic, C#–Tcl/Tk(maybe)– Javascript• fundamental ideas– interface components: widgets, controls, objects, …– methods, properties– events: loops and callbacks– geometry and layout management– use of hierarchy, inheritance• the GUI is the biggest chunk of code in many applications– libraries try to make it easier– development environments and wizards and builders try to make it easier– it's still hardX Windows (Bob Scheifler, Jim Gettys, mid-1980's)• client-server over a network– works on single machine too, with IPC• variants:– X terminal (e.g., SunRay): server is standalone– workstation: server is on same processor as clients– remote clients, local server– Exceed: server on PC, clients on (usually) Unix• window manager is just another client, but with more properties– clients have to let the window manager manage– InterClient Communications Conventions Manualclient client WM clientserverdisplaymousekeyboardnetwork2X Windows model (www.x.org)• serverruns on the local machine– accepts network (or local) client requests and acts on them– creates, maps and destroys windows– writes and draws in windows – manages keyboard, mouse and display– sends keyboard and mouse events back to proper clients– replies to information requests– reports errors• client application– written with X libraries (i.e. Xlib, Xt) – uses the X protocol tosend requests to the serverreceive replies, events, errors from server• protocol messages– requests: clients make requests to the servere.g., Create Window, Draw, Iconify, ... – replies: server answers queries ("how big is this?")–events: server forwards events to client typically keyboard or mouse input – errors: server reports request errors to client X Windows programming model• Xlib provides client-server communication• intrinsics provide basic operations for building and combining widgets• widgets implement user interface components– buttons, labels, dialog boxes, menus, …– multiple widget sets, e.g., Motif• application uses all of these layersXlibXt intrinsicswidgetsapplication3Xlib: bottom level library• basic mechanisms for– requests from client to server: "draw on window", "how big is this?"– replies from server to client: "this big"– events from server to client: "button 1 pushed", "window exposed"– error reports: "out of memory"• basic Xlib-level client program– connect client to server: XOpenDisplay()– get info about screen, compute desired size for window;hints, not mandatory; the WM is in charge– create window: XCreateSimpleWindow()– set standard properties for window managersizes, window name, icon name, ...– select events to be received and discarded– create "graphics context" for storing info on color, depth, ...things that don't change from request to requestserver caches this info to cut down traffic– display window: XMapWindow()causes it to appear; up to this point it hasn't– loop on eventsEvents• client registers for events it cares about• events occur asynchronously• queued for each client• client has to be ready to handle events any time– mouse buttons or motion– keyboard input– window moved or reshaped or exposed– 30-40 others• information comes back to client in a giant union XEventXevent myevent;for (;;) {XNextEvent(mydisplay, &myevent);switch (myevent.type) {case ButtonPress: …...4Hello world in X toolkit/ Motif widgets#include <Xm/XmAll.h>void main(int argc, char *argv[]){Widget toplevel, main_w, button;XtAppContext app;XtSetLanguageProc(NULL, NULL, NULL);toplevel = XtVaAppInitialize(&app, "main", NULL, 0,&argc, argv, NULL, NULL);main_w = XtVaCreateManagedWidget("main_w",xmMainWindowWidgetClass,toplevel, XmNscrollingPolicy, XmAUTOMATIC, NULL);button = XtVaCreateWidget("Hello World",xmLabelWidgetClass, main_w, NULL);XtManageChild(button);XtRealizeWidget(toplevel);XtAppMainLoop(app); }/* cc x.c -lXm -lXt -lX11 */Hello world in GTk (plus ça change…)#include <gtk/gtk.h>static void hello( GtkWidget *widget, gpointer data ) {g_print ("Hello World\n");}static gboolean delete_event( GtkWidget *widget, GdkEvent *event,gpointer data ) {g_print ("delete event occurred\n");return TRUE;}static void destroy( GtkWidget *widget, gpointer data ) {gtk_main_quit ();}int main( int argc, char *argv[] ) {GtkWidget *window;GtkWidget *button;gtk_init (&argc, &argv);window = gtk_window_new (GTK_WINDOW_TOPLEVEL);g_signal_connect (G_OBJECT (window), "delete_event",G_CALLBACK (delete_event), NULL);g_signal_connect (G_OBJECT (window), "destroy",G_CALLBACK (destroy), NULL);gtk_container_set_border_width (GTK_CONTAINER (window), 10);button = gtk_button_new_with_label ("Hello World");g_signal_connect (G_OBJECT (button), "clicked",G_CALLBACK (hello), NULL);g_signal_connect_swapped (G_OBJECT (button), "clicked",G_CALLBACK (gtk_widget_destroy),G_OBJECT (window));gtk_container_add (GTK_CONTAINER (window), button);gtk_widget_show (button);gtk_widget_show (window);gtk_main ();return 0;}5Graphical user interfaces in Java• interfaces built from components– buttons, labels, text areas, lists, menus, dialogs, ...– canvas: graphics for drawing and image rendering• each component has – properties: size, position, visibility, text, font, color, …– methods: things it will do, e.g., change properties– events: external stimuli it responds to• containers: hold components and containers• layout managers: control size, placement of objects within a container(Campione & WalrathJava Tutorial)6Component object hierarchyObject -> Component -> Container-> Jcomponent-> Jpanel-> Jlabel-> JButton-> JTextComponent-> JTextField-> JPasswordField-> JTextArea-> …• containers hold components and containers– used to build up nested structures– JFrame: top-level window– Jpanel: general container for components & containersput JPanels in a JFrame– JMenuBar for menubar across top of frame• individual components like Jbutton, Jtext…– respond to events– have methods for other behaviors– have get and set methods for accessing propertieslike size, color, fontLayout hierarchy• JFrame holds one or more JPanels• JPanel holds components and other Jpanels• JPanel used for layout– add() method adds components– uses a LayoutManager that lays out components– layout manager can be set to one of severalJPanelJPanelJPanel7Events•


View Full Document

Princeton COS 333 - Graphical user interfaces

Download Graphical user interfaces
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Graphical user interfaces and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Graphical user interfaces 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?