I'm trying to implement simple sample about using JRadioButton and i don't know Why some Buttons works and others not
That is my code...
GeSHi (java):
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.lang.reflect.InvocationTargetException;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
public class RadioButtonFrame
extends JFrame {
private static final long serialVersionUID = -4257293733892482733L;
private Font plainFont =
null;
private Font italicFont =
null;
private Font boldFont =
null;
private Font italic_bold_Font =
null;
public RadioButtonFrame()
{
super("Testing RadioButton");
setDefaultCloseOperation
(JFrame.
EXIT_ON_CLOSE);
setSize(300, 100);
textField =
new JTextField("Watch the font style change",
25);
add(textField);
italicboldRadioButton =
new JRadioButton("Bold/Italic",
false);
add(plainRadioButton);
add(italicRadioButton);
add(boldRadioButton);
add(italicboldRadioButton);
//Create Logical relationship between JRadioButton.
radioGroup.add(plainRadioButton);
radioGroup.add(italicRadioButton);
radioGroup.add(boldRadioButton);
radioGroup.add(italicboldRadioButton);
//Create font objects.
plainFont =
new Font("Serif",
Font.
PLAIN,
14);
italicFont =
new Font("Serif",
Font.
ITALIC,
14);
boldFont =
new Font("Serif",
Font.
BOLD,
14);
italic_bold_Font =
new Font("Serif",
Font.
BOLD +
Font.
ITALIC ,
14);
textField.setFont(plainFont);
//Register events for JRadioButton.
plainRadioButton.addItemListener(new RadioButtonHandler(plainFont));
italicboldRadioButton.addItemListener(new RadioButtonHandler(italicFont));
boldRadioButton.addItemListener(new RadioButtonHandler(boldFont));
italicboldRadioButton.addItemListener(new RadioButtonHandler(italic_bold_Font));
setVisible(true);
}
private Font font =
null ;
public RadioButtonHandler
(Font f
){ font = f ;
}
@Override
textField.setFont(font);
}
}
@Override
public void run() {
new RadioButtonFrame();
}
});
}
}
Created by GeSHI 1.0.7.20
Another thing about Generated Code for Class what's the benefit about this
Is this like CLSID in COM Objects in C++ programming.