import java.awt.*;
import java.awt.event.ActionEvent;import java.awt.event.ActionListener;
import javax.swing.*;
public class CheckBoxTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
EventQueue.invokeLater(new Runnable() {
public void run()
{
CheckBoxFrame frame = new CheckBoxFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class CheckBoxFrame extends JFrame {
private static final int DEFAULT_WIDTH = 300;
private static final int DEFAULT_HEIGHT = 200;
private static final int FONTSIZE = 20;
private JLabel label;
private JCheckBox bold;
private JCheckBox italic;
public CheckBoxFrame() {
setTitle("CheckBoxTest");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
JPanel southPanel = new JPanel();
bold = new JCheckBox("Bold");
italic = new JCheckBox("Italic");
southPanel.add(bold);
southPanel.add(italic);
add(southPanel, BorderLayout.SOUTH);
JPanel textPanel = new JPanel();
label = new JLabel("Jun.H Lv Dan.D.Y!");
label.setFont(new Font("Serif", Font.PLAIN, FONTSIZE));
textPanel.add(label);
add(textPanel, BorderLayout.CENTER);
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent event){
int mode = 0;
if (bold.isSelected()) mode += Font.BOLD;
if (italic.isSelected()) mode += Font.ITALIC;
label.setFont(new Font("Serif", mode, FONTSIZE));
}
};
bold.addActionListener(listener);
italic.addActionListener(listener);
}
}