Thinking in Java第三版书中的源代码

源代码在线查看: lookandfeel.java

软件大小: 406 K
上传用户: zp380747972
关键词: Thinking Java in 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				//: c14:LookAndFeel.java
				// Selecting different looks & feels.
				// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
				// www.BruceEckel.com. See copyright notice in CopyRight.txt.
				import javax.swing.*;
				import java.awt.*;
				import java.awt.event.*;
				import java.util.*;
				import com.bruceeckel.swing.*;
				
				public class LookAndFeel extends JFrame {
				  private String[] choices = {
				    "eeny","meeny","Minnie","Mickey","Moe","Larry","Curly"
				  };
				  private Component[] samples = {
				    new JButton("JButton"),
				    new JTextField("JTextField"),
				    new JLabel("JLabel"),
				    new JCheckBox("JCheckBox"),
				    new JRadioButton("Radio"),
				    new JComboBox(choices),
				    new JList(choices),
				  };
				  public LookAndFeel() {
				    super("Look And Feel");
				    Container cp = getContentPane();
				    cp.setLayout(new FlowLayout());
				    for(int i = 0; i < samples.length; i++)
				      cp.add(samples[i]);
				  }
				  private static void usageError() {
				    System.out.println(
				      "Usage:LookAndFeel [cross|system|motif]");
				    System.exit(1);
				  }
				  public static void main(String[] args) {
				    if(args.length == 0) usageError();
				    if(args[0].equals("cross")) {
				      try {
				        UIManager.setLookAndFeel(UIManager.
				          getCrossPlatformLookAndFeelClassName());
				      } catch(Exception e) {
				        e.printStackTrace();
				      }
				    } else if(args[0].equals("system")) {
				      try {
				        UIManager.setLookAndFeel(UIManager.
				          getSystemLookAndFeelClassName());
				      } catch(Exception e) {
				        e.printStackTrace();
				      }
				    } else if(args[0].equals("motif")) {
				      try {
				        UIManager.setLookAndFeel("com.sun.java."+
				          "swing.plaf.motif.MotifLookAndFeel");
				      } catch(Exception e) {
				        e.printStackTrace();
				      }
				    } else usageError();
				    // Note the look & feel must be set before
				    // any components are created.
				    Console.run(new LookAndFeel(), 300, 200);
				  }
				} ///:~			

相关资源