SHARE
TWEET

Untitled

a guest Mar 26th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package checkboxtest;
  2. import java.awt.FlowLayout;
  3. import java.awt.Font;
  4. import java.awt.event.ItemListener;
  5. import java.awt.event.ItemEvent;
  6. import javax.swing.JFrame;
  7. import javax.swing.JTextField;
  8. import javax.swing.JCheckBox;
  9.  
  10. public class CheckBoxFrame extends JFrame {
  11.     private JTextField textField;
  12.     private JCheckBox boldJCheckBox;
  13.     private JCheckBox italicJCheckBox;
  14.    
  15. public CheckBoxFrame(){
  16.     super( "JCheckBox Test" );
  17.     setLayout(new FlowLayout());
  18.    
  19.     textField = new JTextField("Watch the font style change",20);
  20.    
  21.     add(textField);
  22.    
  23.     boldJCheckBox = new JCheckBox("Bold");
  24.     italicJCheckBox = new JCheckBox("italic");
  25.     add( boldJCheckBox );
  26.     add( italicJCheckBox );
  27.    
  28.     CheckBoxHandler handler = new CheckBoxHandler();
  29.     boldJCheckBox.addItemListener(handler);
  30.     italicJCheckBox.addItemListener(handler);
  31. }
  32. private class CheckBoxHandler implements ItemListener{
  33.     public void itemStateChanged(ItemEvent event){
  34.         Font font = null;
  35.         if(boldJCheckBox.isSelected() && italicJCheckBox.isSelected()){
  36.             font = new Font(" Serif",Font.BOLD + Font.ITALIC,14);
  37.         }else if(boldJCheckBox.isSelected()){
  38.             font = new Font("Serif",Font.BOLD,14);
  39.         }else if(italicJCheckBox.isSelected()){
  40.             font = new Font("Serif",Font.ITALIC,14);
  41.         }else
  42.             font = new Font ("Serif",Font.PLAIN,14);
  43.             textField.setFont( font );
  44.         }
  45.        
  46.     }
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top