Basic GUI Flashcards
What form of programming do graphical user interfaces tend to use?
Event-driven programming
What are the GUI packages used in Java?
AWT is the older framework. It involves “heavy-weight” components that use native system GUI elements
Swing is the newer version. Most components are lightweight.
What are heavyweight GUI components?
Those that use native system GUI elements
What is the naming convention for Java GUI frameworks?
AWT elements have no prefix i.e. “Component”
Swing components use J as a prefix i.e. “JComponent”
What are the basic GUi components?
Windows - top level containers i.e. frame and dialog box
Components - GUI widgets i.e. button, label
Containers - logical grouping for components i.e panel
How are dialog boxes created?
Using the static methods of JOptionPane i.e. .showInputDialog(“…”) and .showMessageDialog(null, “…”)
How does the showInputDialog static method work?
Returns the string that the user enters or null if they press cancel.
How does the showMessageDialog static method work?
First argument is where to display the alert. Use null for centre.
The second argument is the message to display.
Third argument is the title
Fourth is the type of message to display, using enums i.e. JOptionPane.ERROR_MESSAGE
What GUI component allows colours to be selected? What does it return?
JColorChooser.
It returns a color of type Color, or null if the user presses cancel
What is a frame?
A frame (i.e. JFrame) is a graphical window that holds other components. It includes a border and title bar.
The visible area of the Frame is a Container. It can be accessed by calling getContentPane()
How are components added to a frame?
getContentPane().add(component)
This returns a Container
What are the steps for creating a new frame?
// Create it JFrame frame = new JFrame()
// Set close operation frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
// add components frame.getContentPane().add(...)
// make it visible
frame. setSize(400, 200)
frame. setVisible(true)
What GUI component is used to group GUI elements?
A JPanel
How are components added to panels?
With .add() i.e. panel.add(new JButton(“OK”))
How are labels created?
JLabel label = new JLabel(“Hello”)
How are buttons created?
JButton button = new JButton(“hello”)