Lecture9-1
Lecture9-1
Lecture 9-1
GUIs
Emily Navarro
Announcements
• Frame Windows
• Event Handling
• Layout Management
• Processing Text Input
• Choices
• Menus
• GUI Builders
• Frame Windows
• Event Handling
• Layout Management
• Processing Text Input
• Choices
• Menus
• GUI Builders
• Frame Windows
• Event Handling
• Layout Management
• Processing Text Input
• Choices
• Menus
• GUI Builders
• Frame Windows
• Event Handling
• Layout Management
• Processing Text Input
• Choices
• Menus
• GUI Builders
• Components are placed toward areas of a container NORTH, EAST, SOUTH, WEST, or
CENTER
• Specify one when adding components:
panel.setLayout(new BorderLayout());
panel.add(component, BorderLayout.NORTH);
• Components expand to fill space
• Frame Windows
• Event Handling
• Layout Management
• Processing Text Input
• Choices
• Menus
• GUI Builders
• Use the setText or append method to set/append to the text of a text field or
text area
textArea.append(balance + "\n");
• Frame Windows
• Event Handling
• Layout Management
• Processing Text Input
• Choices
• Menus
• GUI Builders
• Add text “items” to a combo box that will show in the list:
JComboBox facenameCombo = new JComboBox();
facenameCombo.addItem("Serif");
facenameCombo.addItem("SansSerif");
. . .
• Use the getSelectedItem method to return the selected item (as an Object)
• Combo boxes can store other objects in addition to strings, so casting to a String
may be required:
String selectedString = (String) facenameCombo.getSelectedItem();
• Frame Windows
• Event Handling
• Layout Management
• Processing Text Input
• Choices
• Menus
• GUI Builders
• Frame Windows
• Event Handling
• Layout Management
• Processing Text Input
• Choices
• Menus
• GUI Builders
• User-interface events include key presses, mouse moves, button clicks, menu
selections, etc.
• An event listener’s (ActionListener) methods describe the actions to be
taken when an event occurs
• UI components are arranged by placing them inside containers
• Each container has a layout manager that directs the arrangement of its
components
• Use a JTextField for reading a single line of input, a JLabel next to each text
field, and a JTextArea to show multiple lines of text
• Use radio buttons for a small set of mutually exclusive choices, a check box for a
binary choice, or a combo box for a large set of choices
• A frame contains a menu bar, which contains menus, which contains submenus and
menu items
Text questions to (562) 684-8307
Announcements