120 likes | 248 Vues
Explore the fundamentals of event-driven programming and graphical user interface (GUI) development in Java. This guide breaks down the interaction between the user and program, emphasizing event handling and the Model-View-Controller (MVC) paradigm. Learn how user actions, such as mouse clicks and button presses, trigger events that drive application logic. This comprehensive overview covers key components, including applets, JFrame, and essential GUI elements like buttons, text fields, and menus, providing a foundational understanding necessary for any aspiring Java developer.
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)