GUI Flashcards
What is GUI
• Graphical User Interface, abbreviated GUI, is a type of
interface that takes advantage of a computer’s graphic ability to allow users to interact with electronic devices through graphical icons and visual indicators.
What are the two packages that generate GUI components in Java
- java.awt
* javax.swing
Compare and contrast AWT and SWING
AWT
• Heavyweight components
• Associated with native components called peers
• Same behaviour, but platform-dependent look
• Package java.awt
Swing • Lightweight components, i.e., no peer components • Same look and feel across platforms • Support pluggable look and feel • Package javax.swing
*See doc for pic
Describe a container, a top level container and give examples
In Java, all GUI objects go into a Container.
• A top level container can stand alone in a web
browser or in an operating system. The two most common top-level containers are:
• JFrame
• JApplet
• Some containers may only be added to other containers.
• JPanel
Describe layout managers and their role
• Associated with containers
• Automate the layout of elements
• When elements are added to the container
• When the window is resized
• automatically adjust the positions and sizes of the
elements.
What is the hierarchy of layout managers?
Container- Layout Manager-
- Border layout, Card Layout, FlowLayout, GridLayout
- LayoutManager2-GridBagLayout
*See doc for pic
Can you identify the design pattern used
here?(Border layout, Card Layout, FlowLayout, GridLayout)
*See doc for pic
Describe events
- A way for GUI components to communicate with the rest of application
- Implemented as event classes (e.g., ActionEvent)
Describe event sources
- Components generating events
* Examples: buttons, check boxes, combo boxes, etc.
Describe event listeners/ handlers
• Objects that receives and processes events
• Must implement an appropriate listener
interface
• Must inform the source its interest in handling a
certain type of events (by registering)
• May listen to several sources and different
types of events
Give an example to show how events, event sources and even handlers work together
[create a button] JButton button = new JButton(“Increment”);
[register an action listener] button.addActionListener(new ButtonActionListener());
[Action listener class] class ButtonActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
[ handle the event e …]
System.out.println(“Increment button pressed!”);
}
}
Give examples of events and their respective listeners
ActionEvent - ActionListener ComponentEvent -ComponentListener ,ComponentAdapter FocusEvent-FocusListener ,FocusAdapter KeyEvent-KeyListener ,KeyAdapter MouseEvent- MouseListener ,MouseAdapter MouseMotionListener-MouseMotionAdapter WindowEvent-WindowListener ,WindowAdapter ItemEvent- ItemListener TextEvent- TextListener
Explain what a JOptionPane is.
The JOptionPane class is used to provide standard dialog boxes such as message dialog box, confirm dialog box and input dialog box. These dialog boxes are used to display information or get input from the user. The JOptionPane class inherits JComponent class.
What is the syntax of using a JOptionPane
import javax.swing.*; public class OptionPaneExample { JFrame f; OptionPaneExample(){ f=new JFrame(); JOptionPane.showMessageDialog(f,"Hello, Welcome to Javatpoint."); } public static void main(String[] args) { new OptionPaneExample(); } } Ou