daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package SciprCodigo;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.*;
  5. public class CheckboxFrame extends JFrame{
  6.     private JTextField textField;
  7.     private JCheckBox boldJCheckBox;
  8.     private  JCheckBox italicJCheckBox;
  9.  
  10.     public CheckboxFrame() {
  11.         super("JCheckBox teste");
  12.         setLayout(new FlowLayout());
  13.  
  14.         textField = new JTextField("Selecione o estilo da fonte", 20);
  15.         textField.setFont(new Font("Serif", Font.PLAIN, 14));
  16.         add(textField);
  17.  
  18.         boldJCheckBox = new JCheckBox("Bold");
  19.         italicJCheckBox = new JCheckBox("Italic");
  20.         add(boldJCheckBox);
  21.         add(italicJCheckBox);
  22.  
  23.         CheckBoxHandler handler = new CheckBoxHandler();
  24.         boldJCheckBox.addItemListener(handler);
  25.         italicJCheckBox.addItemListener(handler);
  26.     }
  27.  
  28.     private class CheckBoxHandler implements ItemListener {
  29.         public void itemStateChanged(ItemEvent event) {
  30.             Font font = null;
  31.             if(boldJCheckBox.isSelected() && italicJCheckBox.isSelected() ) {
  32.                 font = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
  33.             }else if(boldJCheckBox.isSelected()) {
  34.                 font = new Font("Serif", Font.BOLD, 14);
  35.             }else if(italicJCheckBox.isSelected()) {
  36.                 font = new Font("Serif", Font.PLAIN, 14);
  37.             }
  38.             textField.setFont(font);
  39.         }
  40.     }
  41. }
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
 
Top