Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- class CheckBoxExample extends JFrame {
- public CheckBoxExample() {
- setTitle("Checkbox Example");
- setSize(300, 200);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JPanel panel = new JPanel();
- add(panel);
- JCheckBox checkBox = new JCheckBox("Check Me");
- panel.add(checkBox);
- checkBox.addItemListener(new ItemListener() {
- public void itemStateChanged(ItemEvent e) {
- if (e.getStateChange() == ItemEvent.SELECTED) {
- System.out.println("Checkbox selected");
- } else {
- System.out.println("Checkbox deselected");
- }
- }
- });
- }
- }
- public class GUI{
- public static void main(String[] args) {
- CheckBoxExample example = new CheckBoxExample();
- example.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement