JCheckBoxTest.java Simple example illustrating the use of check boxes. import javax.swing.*; import java.awt.event.*; */ public class JCheckBoxTest extends JPanel implements ItemListener, ActionListener{ JCheckBox checkBox1, checkBox2; public JCheckBoxTest() { checkBox1 = new JCheckBox("Java Servlets"); checkBox2 = new JCheckBox("JavaServer Pages"); checkBox1.setContentAreaFilled(false); checkBox2.setContentAreaFilled(false); checkBox1.addItemListener(this); checkBox2.addActionListener(this); add(checkBox1); add(checkBox2); } public void actionPerformed(ActionEvent event) { System.out.println("JavaServer Pages selected: " + checkBox2.isSelected()); } public void itemStateChanged(ItemEvent event) { JCheckBox checkbox = (JCheckBox)event.getItem(); if (event.getStateChange() == ItemEvent.SELECTED) { System.out.println(checkbox.getText() + " selected."); } else { System.out.println(checkbox.getText() + " deselected."); } } public static void main(String[] args) { JPanel panel = new JCheckBoxTest(); WindowUtilities.setNativeLookAndFeel(); WindowUtilities.openInJFrame(panel, 300, 75); } }
Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10317
Categories:Programming Code Examples, Java/J2EE/J2ME, Basic Swing
Tags:Java/J2EE/J2MEBasic Swing
Post Data:2017-01-02 16:04:31
Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada