package mypackage;
import javax.swing.*;
import java.awt.event.*;public class Console
{
//Creat a title string from the class name
public static String title(Object o)
{
String t = o.getClass.toString(); //不能识别变量getClass
//Remove the word "class"
if(t.indexof("class") != -1) //不能识别indexof()方法
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(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(titile(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)); //不能识别title()方法
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.setSize(width,height);
frame.setVisible(true);
}
}上面程序注释的地方总是出错误,为什么呀?我可是按照书本上写的!!
import javax.swing.*;
import java.awt.event.*;public class Console
{
//Creat a title string from the class name
public static String title(Object o)
{
String t = o.getClass.toString(); //不能识别变量getClass
//Remove the word "class"
if(t.indexof("class") != -1) //不能识别indexof()方法
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(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(titile(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)); //不能识别title()方法
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.setSize(width,height);
frame.setVisible(true);
}
}上面程序注释的地方总是出错误,为什么呀?我可是按照书本上写的!!
getClass是方法,而不是变量,因此因该是getClass()
indexOf()是String类的方法,但是是indexOf(),而不是indexof()
title()应该是自定义的方法,如果我猜的没错
这个方法应该是
public String title(JPanel panel)
{
return panel.getTitle();
}
找不到程序入口点;
getclass()方法不是getclass()
是indexOf(),而不是indexof()
String t = o.getClass().toString();
2.indexOf是String类下面的一个方法:它在String类中的申明是这样的:
public int indexOf(String str), 所以方法名是indexOf,而不是indexof.
3.title应该是这本书的编者自己写的一个方法,估计是这样的:
public String title(JPanel panel){
return panel.getUIClassID();
}
建议: 多查阅JDK文档。