ackage taoshi.a6;
import javax.swing.*;
import java.awt.event.*;
public class Adisplay  {
public static String title(Object o) {
String t=o.getClass().toString();
if(t.indexOf("class"!=-1)) {
t=t.substring(6);
return t;
}
public static void setupClosing (JFrame frame) {
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
public static void
                  run (JFrame frame,int widthint ,height) {
setupClosing(frame);
frame.setSize(wideth,height);
frame.setVisible(true);
}
public static void
run (JApplet applet,int width,int height) {
JFrame frame=new JFrame(title(applet));
setupClosing(frame);
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));
setupClosing(frame);
frame.getContentPane().add(panel);
frame.setSize(width,height);
frame.setVisible(true);
}
}
}}
怎么搞的有四处错误,这是书上的原程序啊。怎么把错误消除啊

解决方案 »

  1.   

    第一行 ackage 应为 package
      

  2.   

    书上的例子有错误很常见的。
    建议你用一个IDE工具,例如Eclipse,它会提示你有哪些错误,以及建议的改正方法。
      

  3.   

    if(t.indexOf("class"!=-1))应为
    if(t.indexOf("class")!=-1)
      

  4.   

    是你超错了还是书错了?? 这么多错误,我给你该了 你对照看看 到底谁错了.....
    package taoshi.a6;import javax.swing.*;
    import java.awt.event.*;public class Adisplay {
    public static String title(Object o) {
    String t=o.getClass().toString();
    if(t.indexOf("class")!=-1) {
    t=t.substring(6);
    }
    return t;}
    public static void setupClosing(JFrame frame){
    frame.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    }
    });}
    public static void
                      run (JFrame frame,int widthint ,int height) {
    setupClosing(frame);
    frame.setSize(widthint,height);
    frame.setVisible(true);
    }
    public static void run (JApplet applet,int width,int height) {
    JFrame frame=new JFrame(title(applet));
    setupClosing(frame);
    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));
    setupClosing(frame);
    frame.getContentPane().add(panel);
    frame.setSize(width,height);
    frame.setVisible(true);
    }}