Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package checkboxtest;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class CheckBoxFrame extends JFrame {
- private final JTextField textField;
- private final JCheckBox boldJCheckBox;
- private final JCheckBox italicJCheckBox;
- public CheckBoxFrame() {
- super( "JCheckBox Test" );
- setLayout( new FlowLayout() );
- textField = new JTextField( "Watch the font style change", 20 );
- italicJCheckBox = new JCheckBox( "Italic" );
- textField.setFont( new Font( "Serif", Font.PLAIN, 14));
- add( textField );
- boldJCheckBox = new JCheckBox( "Bold" );
- add( boldJCheckBox );
- add( italicJCheckBox );
- CheckBoxHandler handler = new CheckBoxHandler();
- boldJCheckBox.addItemListener( handler );
- italicJCheckBox.addItemListener( handler );
- }
- private class CheckBoxHandler implements ItemListener{
- @Override
- public void itemStateChanged( ItemEvent event ){
- Font font = null;
- if (boldJCheckBox.isSelected () && italicJCheckBox.isSelected()){
- font = new Font ("Serif", Font.BOLD + Font.ITALIC, 14);
- } else {
- if (boldJCheckBox.isSelected()) {
- font = new Font ("Serif", Font.BOLD, 14);
- } else {
- if (italicJCheckBox.isSelected()) {
- font = new Font ("Serif", Font.ITALIC, 14);
- } else {
- font = new Font ("Serif", Font.PLAIN, 14);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement