Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package radiobuttontest;
- import java.awt.FlowLayout;
- import java.awt.Font;
- import java.awt.event.ItemListener;
- import java.awt.event.ItemEvent;
- import javax.swing.JFrame;
- import javax.swing.JTextField;
- import javax.swing.JRadioButton;
- import javax.swing.ButtonGroup;
- class RadioButtonFrame extends JFrame{
- private JTextField textField;
- private Font plaintFont;
- private Font boldFont;
- private Font boldItalicFonte;
- private JRadioButton plainJRadioButton;
- private JRadioButton boldJRadioButton;
- private JRadioButton ItalicJRadioButton;
- private JRadioButton boldItalicJRadioButton;
- private ButtonGroup radioGroup;
- private final Font plainFont;
- private final Font italicFont;
- private final Font boldItalicFont;
- public RadioButtonFrame(){
- super ("RadioButton Test");
- setLayout (new FlowLayout());
- textField = new JTextField("Watch the font style change", 25);
- add (textField);
- plainJRadioButton = new JRadioButton ("Plain", true);
- boldJRadioButton = new JRadioButton ("Bold", false);
- ItalicJRadioButton = new JRadioButton ("Italic", false);
- boldItalicJRadioButton = new JRadioButton ("Bold/Italic", false);
- add (plainJRadioButton);
- add (boldJRadioButton);
- add (ItalicJRadioButton);
- add (boldItalicJRadioButton);
- radioGroup = new ButtonGroup();
- radioGroup.add (plainJRadioButton);
- radioGroup.add (boldJRadioButton);
- radioGroup.add (ItalicJRadioButton);
- radioGroup.add (boldItalicJRadioButton);
- plainFont = new Font ("Serif", Font.PLAIN, 14);
- boldFont = new Font ("Serif", Font.BOLD, 14);
- italicFont = new Font ("Serif", Font.ITALIC, 14);
- boldItalicFont = new Font ("Serif", Font.BOLD + Font.ITALIC, 14);
- textField.setFont (plainFont);
- plainJRadioButton.addItemListener(
- new RadioButtonHandler (plainFont));
- boldJRadioButton.addItemListener(
- new RadioButtonHandler (boldFont));
- ItalicJRadioButton.addItemListener
- ( new RadioButtonHandler (italicFont));
- boldItalicJRadioButton.addItemListener(
- new RadioButtonHandler (boldItalicFont));
- }
- private class RadioButtonHandler implements ItemListener {
- private Font font;
- public RadioButtonHandler ( Font F){
- font = F;
- }
- public void itemStateChanged (ItemEvent event){
- textField.setFont ( font );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement