check boxes & radio buttons

check boxes & radio buttons - CSc 2700 Lecture 21...

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

View Full Document Right Arrow Icon
CSc 2700: Lecture # 21 Check Boxes and Radio Buttons November 11, 2008 1 Introduction Two components that can be used for simple input are check boxes and radio buttons. The main diFerence between check boxes and radio buttons is that ±igure 1: ±our Check Boxes and Three Radio Buttons you may check or select any number of check boxes in a group but only one radio button. 2 JCheckBox A check box is a component that can be either selected or not, i.e., switched, or toggled on or oF. If a check box, with only two possible states, seems like a button, it should be no surprise that JCheckBox extends AbstractButton. Here are the basics: Class: JCheckBox Generates: ActionEvent and ItemEvent when the state of a check box changes. Listener: Must implement ActionListener to respond to an ActionEvent and ItemListener to respond to an ItemEvent. Listener method to implement: void actionPerformed( ActionEvent e) for ActionListener void itemStateChanged(ItemEvent e) for ItemListener Register a listener : void addActionListener(ActionListener actionListener) ( for ActionListener interface) void addItemListener(ItemListener itemListener) ( for ItemListener interface) 1
Background image of page 1

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

View Full Document Right Arrow Icon
Constructor : JCheckBox() creates an unselected check box with no text. JCheckBox(String text) creates an unselected check box with accompanying text text. JCheckBox(String text, boolean selected) creates a check box with text text. If selected is true the check box is initially selected. JCheckBox(Icon image)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 5

check boxes & radio buttons - CSc 2700 Lecture 21...

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

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