import javax.swing.*;
import java.awt.*;
import javawork.swing.*;
class Button1 extends JApplet
{
private JButton
   b1 =new JButton("Button1"),
   b2 =new JButton("Button2");
  public void init()
  {
   Container cp = getContentPane();
   //FlowLayOut使得控件可以在窗体上从左到右,从上到下连续均匀分布
   cp.setLayout(new FlowLayout());
   cp.add(b1);
   cp.add(b2);
  }
  public static void main(String [] args)
  {
   Console.run(new Button1(),200,100);
  }
}
其中import javawork.swing.*;是从com.bruceeckel.swing 那里复制过来的
我运行后 为啥界面没有那两个按钮呢???

解决方案 »

  1.   

    我的有显示啊...
    Console是这个import javax.swing.*;
    import java.awt.event.*;public class Console {
      // Create a title string from the class name:
      public static String title(Object o) {
        String t = o.getClass().toString();
        // Remove the word "class":
        if(t.indexOf("class") != -1)
          t = t.substring(6);
        return t;
      }
      public static void 
      run(JFrame frame, int width, int height) {
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(width, height);
        frame.setVisible(true);
      }
      public static void 
      run(JApplet applet, int width, int height) {
        JFrame frame = new JFrame(title(applet));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(applet);
        frame.setSize(width, height);
        applet.init();
        applet.start();
        frame.setVisible(true);
      }
      public static void 
      run(JPanel panel, int width, int height) {
        JFrame frame = new JFrame(title(panel));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(panel);
        frame.setSize(width, height);
        frame.setVisible(true);
      }
    } ///:~
      

  2.   

    Button1类里再去掉这行不就行了
    import javawork.swing.*;
      

  3.   

    还有以后运行的每个按钮就为啥都加不上呢,面板上都没显示,我用的是jdk1.5.0版本的
    不会我下载的 这个jdk有问题吧???不过还是能运行的啊。就是跟想要的结果不同!!
      

  4.   

    那个think in java 3th是jdk1.4.2下的代码,
    1.5应该没问题的咱俩代码都一样结果不一样??
    不太可能吧...
    你在复制一遍试试吧import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;public class Console {
      // Create a title string from the class name:
      public static String title(Object o) {
        String t = o.getClass().toString();
        // Remove the word "class":
        if(t.indexOf("class") != -1)
          t = t.substring(6);
        return t;
      }
      public static void 
      run(JFrame frame, int width, int height) {
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(width, height);
        frame.setVisible(true);
      }
      public static void 
      run(JApplet applet, int width, int height) {
        JFrame frame = new JFrame(title(applet));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(applet);
        frame.setSize(width, height);
        applet.init();
        applet.start();
        frame.setVisible(true);
      }
      public static void 
      run(JPanel panel, int width, int height) {
        JFrame frame = new JFrame(title(panel));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(panel);
        frame.setSize(width, height);
        frame.setVisible(true);
      }
    } ///:~
    class Button1 extends JApplet
    {
    private JButton
       b1 =new JButton("Button1"),
       b2 =new JButton("Button2");
      public void init()
      {
      Container cp = getContentPane();
      //FlowLayOut使得控件可以在窗体上从左到右,从上到下连续均匀分布
      cp.setLayout(new FlowLayout());
      cp.add(b1);
      cp.add(b2);
      }
      public static void main(String [] args)
      {
      Console.run(new Button1(),200,100);
      }
    }
      

  5.   

    是啊 就可以了,
    我看了看其中的不同之处,是我在把 public static void 
      run(JApplet applet, int width, int height) {
        JFrame frame = new JFrame(title(applet));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(applet);
        frame.setSize(width, height);
        applet.init();
        applet.start();
        frame.setVisible(true);
      }
    中的方法的顺序写的跟原来有所不同
    这样居然就出问题了,真不想到啊。当按照书本上的顺序不变的话,就没有错了,真不知道这是为什么!!!难道这根调用的顺序还有关嘛???
    真后悔把原来写的顺序的代码删了,也忘了是怎么样的了!!