class ControlPanel extends JPanel {
JCheckBox checkBox = new JCheckBox("UIResource");
JRadioButton motifButton = new JRadioButton("Motif"),
windowsButton = new JRadioButton("Windows"),
metalButton = new JRadioButton("Metal");
public ControlPanel() {
ActionListener listener = new RadioHandler();
ButtonGroup group = new ButtonGroup();
group.add(motifButton);
group.add(windowsButton);
group.add(metalButton);
motifButton.addActionListener(listener);
windowsButton.addActionListener(listener);
metalButton.addActionListener(listener);
add(motifButton);
add(windowsButton);
add(metalButton);
}
class RadioHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
JRadioButton src = (JRadioButton) e.getSource();
try {
if (src == motifButton)
UIManager.setLookAndFeel("com.sun.java.swing.plaf."
+ "motif.MotifLookAndFeel");
else if (src == windowsButton)
UIManager.setLookAndFeel("com.sun.java.swing.plaf."
+ "windows.WindowsLookAndFeel");
else if (src == metalButton)
UIManager.setLookAndFeel("javax.swing.plaf.metal."
+ "MetalLookAndFeel");
} catch (Exception ex) {
ex.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(getContentPane());
}
}
}
posted on 2007-01-25 10:38
aaabbb 阅读(721)
评论(0) 编辑 收藏 所属分类:
Swing