Unit 4: Java GUI Flashcards
What is Java’s main library for building GUIs?
Swing (which builds on the older AWT - Abstract Window Toolkit)
Which classes must be imported for GUI development?
import java.awt.; import java.awt.event.; import javax.swing.*;
What is a container in Java GUI?
A component that holds and displays other GUI components (like buttons, text fields).
What class represents a window in Java Swing?
JFrame
What is a JButton used for?
A clickable button that can trigger an ActionEvent.
What is a JTextField?
A field that displays text and can be used for input/output.
How do you add a component to a JFrame?
Use window.add(component); where window is the content pane.
What layout manager arranges components left-to-right, top-to-bottom?
FlowLayout
What interface must be implemented for handling button clicks?
ActionListener
What method is required when implementing ActionListener?
public void actionPerformed(ActionEvent e)
How do you register a button for event handling?
button.addActionListener(this);
How do you check which button triggered an event?
if (e.getSource() == buttonName)