

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to java gui programming, focusing on the use of components, events, listeners, and layout managers. It covers the basics of creating a java program with a gui, including the necessary packages and the creation of various gui elements such as buttons, text fields, checkboxes, and sliders. The document also discusses the role of layout managers in arranging components within a container.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!
Command-line applications , interact with the user through simple prompts and feedback … but they lack the rich user experience With GUI, the user is not limited to responding to prompts in a particular order and receiving feedback in one place Three kinds of objects are needed to create a GUI in Java components events listeners
Component –defines a screen element used to display information or allow the user to interact with the program A container is a special type of component that is used to hold and organize other components Event – an object that represents some occurrence in which we may be interested Often correspond to user actions (mouse button press, key press) Most GUI components generate events to indicate a user action related to that component Program that is oriented around GUI, responding to user events is called event-driver Listener – an object that “waits” for an event to occur and responds in way when it does In designing a GUI-based program we need to establish the relationships between the listener , the event it listens for, and the component that generates the event
instantiate and set up the necessary components, implement listener classes that define what happens when particular events occur, and establish the relationship between the listeners and the components that generate the events of interest
java.awt javax.swing
A variety of interactive components Buttons – of course… text fields –input from keyboard check boxes – a button that can be toggled on or off using the mouse (indicates a boolean value is set or unset) radio buttons –to provide a set of mutually exclusive options sliders – specify a numeric value within a bounded range combo boxes – select one of several options from a “drop down” menu
Every container is managed by a layout manager object that determines how the components in the container are arranged visually Every container has a default layout manager, but we can replace it if desired The layout manager is consulted when needed, such as when the container is resized or when a component is added A layout manager determines the size and position of each component Every layout manager has its own rules and properties governing the layout of the components it contains For some layout managers, the order in which you add the components affects their positioning
Layout Manager Description Border Layout Organizes components into five areas (North, South, East, West, and Center) Box Layout Organizes components into a single row or column Tabbed Layout Organizes components into one area such that only one area is visible at a time Flow Layout Organizes components from left to right, starting new rows as necessary Grid Layout Organizes components into a grid of rows and columns
The easiest layout managers to use The JPanel class uses flow layout by default Puts as many components as possible on a row, at their preferred size When a component can not fit on a row, it is put on the next row
A border layout has five areas to which components can be added: North, South, East, West, and Center The four outer areas are as large as needed in order to accommodate the component they contain If no components are added to a region, the region takes up no room in the overall layout The Center area expands to fill any available space