CheckBoxViewer.java - import javax.swing import java.awt...

This preview shows page 1 - 2 out of 3 pages.

import javax.swing.* ; import java.awt.* ; import java.awt.event.* ; /** To illustrate using radio buttons with check boxes. */ public class CheckBoxViewer { public static final int FRAME_WIDTH = 500 ; public static final int FRAME_HEIGHT = 300 ; public static void main(String[] args) { /** Make the frame */ JFrame frame = new CheckBoxFrame() ; frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ; frame.setTitle("CheckBoxFrame") ; frame.setSize(FRAME_WIDTH, FRAME_HEIGHT) ; frame.setVisible(true) ; } } /** The idea here is to make the message be "Hello, World!" when the radiobutton "hello" is pressed "Goodbye, World!" when the radiobutton "goodbye" is pressed "Hello, cruel World!" when the radiobutton "hello" is pressed and the checkbox "cruel" is checked. "Goodbye, cruel World!" when the radiobutton "goodbye" is pressed and the checkbox "cruel" is checked. */ class CheckBoxFrame extends JFrame { private JRadioButton hello ; private JRadioButton goodbye ; private JCheckBox cruel ; private JTextArea area ; /** Constructs the frame */ public CheckBoxFrame() { area = new JTextArea() ; area.setText("Expected:\nHello, World!\nHello, cruel World!\nGoodbye,

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture