SHARE
TWEET

Untitled

a guest Mar 26th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.FlowLayout;
  2. import java.awt.Font;
  3. import java.awt.event.ItemListener;
  4. import java.awt.event.ItemEvent;
  5. import javax.swing.JFrame;
  6. import javax.swing.JTextField;
  7. import javax.swing.JRadioButton;
  8. import javax.swing.ButtonGroup;
  9. public class RadioButtonFrame extends JFrame {
  10.     private JTextField textField;
  11.     private Font plainFont;
  12.     private Font boldFont;
  13.     private Font italicFont;
  14.     private Font boldItalicFont;
  15.    
  16.     private JRadioButton plainJRadioButton;
  17.     private JRadioButton boldJRadioButton;
  18.     private JRadioButton italicJRadioButton;
  19.     private JRadioButton boldItalicJRadioButton;
  20.     private ButtonGroup radioGroup;
  21.  
  22.     public RadioButtonFrame(){
  23.         super("RadioButton Test");
  24.         setLayout(new FlowLayout());
  25.  
  26.         textField = new JTextField("Veja a fonte mudar", 25);
  27.         add (textField);
  28.  
  29.         plainJRadioButton = new JRadioButton("Normal", true);
  30.         boldJRadioButton = new JRadioButton("Negrito", false);
  31.         italicJRadioButton = new JRadioButton("Itálico", false);
  32.         boldItalicJRadioButton = new JRadioButton("Negrito e Itálico", false);
  33.  
  34.         add(plainJRadioButton);
  35.         add(boldJRadioButton);
  36.         add(italicJRadioButton);
  37.         add(boldItalicJRadioButton);
  38.  
  39.         radioGroup = new ButtonGroup();
  40.         radioGroup.add(plainJRadioButton);
  41.         radioGroup.add(boldJRadioButton);
  42.         radioGroup.add(italicJRadioButton);
  43.         radioGroup.add(boldItalicJRadioButton);
  44.  
  45.         plainFont = new Font("Serif", Font.PLAIN, 14);
  46.         boldFont = new Font("Serif", Font.BOLD, 14);
  47.         italicFont = new Font("Serif", Font.ITALIC, 14);
  48.         boldItalicFont = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
  49.  
  50.         plainJRadioButton.addItemListener(new RadioButtonHandler(plainFont));
  51.         boldJRadioButton.addItemListener(new RadioButtonHandler(boldFont));
  52.         italicJRadioButton.addItemListener(new RadioButtonHandler(italicFont));
  53.         boldItalicJRadioButton.addItemListener(new RadioButtonHandler(boldItalicFont));
  54.     }
  55.  
  56.     private class RadioButtonHandler implements ItemListener{
  57.         private Font font;
  58.  
  59.         public RadioButtonHandler(Font f){
  60.             font = f;
  61.         }
  62.         public void itemStateChanged(ItemEvent event){
  63.             textField.setFont(font);
  64.         }
  65.     }
  66. }
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