偶调试了一些<<Java编程思想2>>P568的程序,好像没有图形的风格呀,只有一个DOS的运行框就没反应了?请问这是怎么回事? 谢谢!!!

解决方案 »

  1.   

    图形的风格??
    编程思想讲的不是这方面的内容啊,你应该看java的swing编程
      

  2.   

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import com.bruceeckel.swing.*;public class LookAndFeel extends JFrame {
      String[] choices = { 
        "eeny", "meeny", "minie", "moe", "toe", "you"
      };
      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(System.err);
          }
        } else if(args[0].equals("system")) {
          try {
            UIManager.setLookAndFeel(UIManager.
              getSystemLookAndFeelClassName());
          } catch(Exception e) {
              e.printStackTrace(System.err);
          }
        } else if(args[0].equals("motif")) {
          try {
            UIManager.setLookAndFeel("com.sun.java."+
              "swing.plaf.motif.MotifLookAndFeel");
          } catch(Exception e) {
              e.printStackTrace(System.err);
          }
        } else usageError();
        // Note the look & feel must be set before
        // any components are created.
        Console.run(new LookAndFeel(), 300, 200);
      }
    }
      

  3.   

    完全可以啊,不过你这里程序有点小问题,你用到了thinking in java 自己写的包import com.bruceeckel.swing.*;如果你机子里面没有或者没有设置路径的话当然没用了,
    还有,这个程序是要对main()传参的,本例用自己写的类Console解决了这个问题,如果你没有这个类的话只能自己在控制行里自己写;
    我把它改了一下完全可一啊;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;public class LookAndFeel extends JFrame {
      String[] choices = { 
        "eeny", "meeny", "minie", "moe", "toe", "you"
      };
      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) {
          try {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
            //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
           //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
          } catch(Exception e) {
              e.printStackTrace(System.err);
          }
        LookAndFeel a=new LookAndFeel();
        a.setSize(600,300);
        a.setVisible(true);
      }
    }