Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class radio_tut extends JFrame{
- private JTextField tf;
- private Font pf;
- private Font bf;
- private Font itf;
- private Font bif;
- private JRadioButton pb;
- private JRadioButton bb;
- private JRadioButton ib;
- private JRadioButton bib;
- private ButtonGroup bgroup;
- public radio_tut(){
- super("Radio Tutorial");
- setLayout(new FlowLayout());
- tf = new JTextField("Bucky is awesome!", 25);
- add(tf);
- pb = new JRadioButton("Plain", true);
- bb = new JRadioButton("Bold", false);
- ib = new JRadioButton("Italic", false);
- bib = new JRadioButton("Bold & Italic", false);
- add(pb);
- add(bb);
- add(ib);
- add(bib);
- bgroup = new ButtonGroup();
- bgroup.add(pb);
- bgroup.add(bb);
- bgroup.add(ib);
- bgroup.add(bib);
- pf = new Font("Serif", Font.PLAIN, 14);
- bf = new Font("Serif", Font.BOLD, 14);
- itf = new Font("Serif", Font.ITALIC, 14);
- bif = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
- tf.setFont(pf);
- pb.addItemListener(new HandlerClass(pf));
- bb.addItemListener(new HandlerClass(bf));
- ib.addItemListener(new HandlerClass(itf));
- bib.addItemListener(new HandlerClass(bif));
- }
- private class HandlerClass implements ItemListener{
- private Font font;
- //font Obj get variable font
- public HandlerClass(Font f){
- font = f;
- }
- //sets font to font passed in
- public void itemStateChanged(ItemEvent event){
- tf.setFont(font);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement