/*
* 创建日期 2004-3-18
*
* 更改所生成文件模板为
* 窗口 > 首选项 > Java > 代码生成 > 代码和注释
*/
package JFCBook.Chapter5.jdk13;/**
* @author Administrator
*
* 更改所生成类型注释的模板为
* 窗口 > 首选项 > Java > 代码生成 > 代码和注释
*/
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;public class Test_Swing {
public static void main(String[]args)
{
TestFrame frame = new TestFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack(); frame.show();
}}
class TestFrame extends JFrame{ public TestFrame()
{
setTitle("Swing Applection");
setSize(400,300);
Container contentPane = getContentPane();
TestPanel panel =new TestPanel();
contentPane.add(panel);
}}class TestPanel extends JPanel implements ActionListener{
private ButtonGroup buttongroup;
private final String metal= "Metal";
private final String metalClassName = "javax.swing.plaf.metal.MetalLookAndFeel"; private final String motif = "Motif";
private final String motifClassName =
"com.sun.java.swing.plaf.motif.MotifLookAndFeel"; private final String windows = "Windows";
private final String windowsClassName =
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
public TestPanel()
{ JButton jbutton = new JButton("Hello World");
buttongroup = new ButtonGroup();
add(jbutton);
addRadioButton(metal,metalClassName);
addRadioButton(motif,motifClassName);
addRadioButton(windows,windowsClassName);
}
public void addRadioButton(String name, final String className)
{ JRadioButton button = new JRadioButton(name);
button.addActionListener(this);
button.setActionCommand(className);
buttongroup.add(button);
add(button);
}
public void actionPerformed(ActionEvent event)
{ try{
UIManager.setLookAndFeel(event.getActionCommand());
SwingUtilities.updateComponentTreeUI(TestPanel.this); }catch(Exception e)
{
e.printStackTrace();
}
}
}
* 创建日期 2004-3-18
*
* 更改所生成文件模板为
* 窗口 > 首选项 > Java > 代码生成 > 代码和注释
*/
package JFCBook.Chapter5.jdk13;/**
* @author Administrator
*
* 更改所生成类型注释的模板为
* 窗口 > 首选项 > Java > 代码生成 > 代码和注释
*/
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;public class Test_Swing {
public static void main(String[]args)
{
TestFrame frame = new TestFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack(); frame.show();
}}
class TestFrame extends JFrame{ public TestFrame()
{
setTitle("Swing Applection");
setSize(400,300);
Container contentPane = getContentPane();
TestPanel panel =new TestPanel();
contentPane.add(panel);
}}class TestPanel extends JPanel implements ActionListener{
private ButtonGroup buttongroup;
private final String metal= "Metal";
private final String metalClassName = "javax.swing.plaf.metal.MetalLookAndFeel"; private final String motif = "Motif";
private final String motifClassName =
"com.sun.java.swing.plaf.motif.MotifLookAndFeel"; private final String windows = "Windows";
private final String windowsClassName =
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
public TestPanel()
{ JButton jbutton = new JButton("Hello World");
buttongroup = new ButtonGroup();
add(jbutton);
addRadioButton(metal,metalClassName);
addRadioButton(motif,motifClassName);
addRadioButton(windows,windowsClassName);
}
public void addRadioButton(String name, final String className)
{ JRadioButton button = new JRadioButton(name);
button.addActionListener(this);
button.setActionCommand(className);
buttongroup.add(button);
add(button);
}
public void actionPerformed(ActionEvent event)
{ try{
UIManager.setLookAndFeel(event.getActionCommand());
SwingUtilities.updateComponentTreeUI(TestPanel.this); }catch(Exception e)
{
e.printStackTrace();
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货