120 likes | 238 Views
COMP 172 Event-driven programing and GUI. Sequential programming. Control Step-by-step under control of the program More like a conversation between program and user Presentation Console text messages, keyboard text input. Event-driven programming. Control Shared between user and program
E N D
Sequential programming • Control • Step-by-step under control of the program • More like a conversation between program and user • Presentation • Console text messages, keyboard text input
Event-driven programming • Control • Shared between user and program • Based on what the user does (events) • Presentation • Graphical, icons, buttons, textfields radio buttons, etc
Event- driven programming • Each component may have one or more associated events • Mouse click, mouse entered, item selected etc • Event listeners are attached to these components and "listen" for the event to occur
Event- driven programming When a listeners detects an event, it calls the associated Event handler Code within each event handler uses application classes to solve the underlying problem Called the Model-View-Controller paradigm.
Structure of software Translation Event handlers take information from the GUI and translate it as needed, then send to application Controller Take what comes back and format it for GUI display Graphical user interface components View This is what the user sees and interacts with Application The classes and methods that solve the problem Model Send info back
Example Application Dog class Translation Button event handler GUI for Dog Feeding
Structure of GUI in Java • Applet • Runs inside browser • Browser is root or primary "window" • Application • Runs independently • JFrame substitutes for main class/method • Acts as the root or primary "window"
Components • To give the user limited choices • Menus • Radio buttons (only one selected) • Checkboxes (multiple selections) • Combo boxes
Components • To allow the user to enter any input • Text fields • Text areas • To make something happen • Buttons (using mouse) • Mouse input (enter, scroll, down/up)