GUIs - Part 3 (13) - COP 3330: Object-Oriented Programming...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 3330: GUIs In Java – Part 3 Page 1 © Dr. Mark Llewellyn COP 3330: Object-Oriented Programming Summer 2011 Introduction To GUIs and Event-Driven Programming In Java – Part 3 Department of Electrical Engineering and Computer Science Computer Science Division University of Central Florida Instructor : Dr. Mark Llewellyn markl@cs.ucf.edu HEC 236, 407-823-2790 http://www.cs.ucf.edu/courses/cop3330/sum2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COP 3330: GUIs In Java – Part 3 Page 2 © Dr. Mark Llewellyn Combo Boxes A combo box , also known as a choice list or drop-down list , contains a list of items from which the user can choose. It is useful in limiting a user’s range of choices and avoids the cumbersome validation of data input. The UML diagram for the JComboBox class is shown on the next page.
Background image of page 2
COP 3330: GUIs In Java – Part 3 Page 3 © Dr. Mark Llewellyn JComboBox JComboBox inherits all the properties from JComponent . A JComboBox can generate an ActionEvent and an ItemEvent , among many other events. javax.swing.JComboBox +JComboBox() +JComboBox(items: Object[]) +addItem(item: Object): void +getItemAt(index: int): Object +getItemCount(): int +getSelectedIndex(): int +setSelectedIndex(index: int): void +getSelectedItem(): Object +setSelectedItem(item: Object): void +removeItem(anObject: Object): void +removeItemAt(anIndex: int): void +removeAllItems(): void Creates a default empty combo box. Creates a combo box that contains the elements in the specified array. Adds an item to the combo box. Returns the item at the specified index. Returns the number of items in the combo box. Returns the index of the selected item. Sets the selected index in the combo box. Returns the selected item. Sets the selected item in the combo box. Removes an item from the item list. Removes the item at the specified index in the combo box. Removes all items in the combo box. javax.swing.JComponent
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
GUIs In Java – Part 3 Page 4 © Dr. Mark Llewellyn Comments on JComboBox JComboBox inherits all the properties from JComponent . A JComboBox can generate an ActionEvent and an ItemEvent , among many other events. Whenever a new item is selected, an ActionEvent is fired. Whenever a new item is selected, JComboBox generates an ItemEvent twice, once for deselecting the previously selected item, and the other for selecting the currently selected item. Note that no ItemEvent is fired if the current item is reselected. To respond to an ItemEvent , you need to implement the itemStateChanged(ItemEvent e) handler for processing a choice. To get data from a JComboBox menu, you can use getSelectedItem() to return the currently selected item, or e.getItem() method to get the item from the itemStateChanged(ItemEvent e) handler. The program on the following pages illustrates the
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 40

GUIs - Part 3 (13) - COP 3330: Object-Oriented Programming...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online