我是初学者,一个很奇怪的问题,请教大家~~
我下载了一个关于swing的例子,可是在jdk1。4下总是出错,程序和出错提示如下:
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class JSplash extends JWindow
implements KeyListener, MouseListener, ActionListener {
/*
* JSplash constructs a splash screen (JWindow).
* parent is the parent frame for the window
* filename is the JPEG/GIF file to show as the splash
* timeout is time in milliseconds to display the splash
*/
public JSplash(JFrame parent, String filename, int timeout) {
super(parent);
// Note, this code does no error checking
ImageIcon image = new ImageIcon(filename);
// The splash will be centered on the screen
int w = image.getIconWidth() + 5;
int h = image.getIconHeight() + 5;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width - w) / 2;
int y = (screen.height - h) / 2;
setBounds(x, y, w, h);
getContentPane().setLayout(new BorderLayout());
JLabel picture = new JLabel(image);
getContentPane().add("Center", picture);
picture.setBorder(new BevelBorder(BevelBorder.RAISED));
// Listen for key strokes
addKeyListener(this);
// Listen for mouse events from here and parent
addMouseListener(this);
parent.addMouseListener(this);
// Timeout after a while
Timer timer = new Timer(0, this);
timer.setRepeats(false);
timer.setInitialDelay(timeout);
timer.start();
}
// This method is called in order to block the application until
// the splash screen times out or is dismissed.
// This is a bit of a kludge, actually, and the actual affect
// varies based on platform.
public void block() {
while(isVisible()) {}
}
// Dismiss the window on a key press, ignore rest.
public void keyTyped(KeyEvent event) {}
public void keyReleased(KeyEvent event) {}
public void keyPressed(KeyEvent event) {
setVisible(false);
dispose();
}
// Dismiss the window on a mouse click, ignore rest.
public void mousePressed(MouseEvent event) {}
public void mouseReleased(MouseEvent event) {}
public void mouseEntered(MouseEvent event) {}
public void mouseExited(MouseEvent event) {}
public void mouseClicked(MouseEvent event) {
setVisible(false);
dispose();
}
// Dismiss the window on a timeout
public void actionPerformed(ActionEvent event) {
setVisible(false);
dispose();
}
}
然后我在jdk1.4目录下 javac F:\JSplash.java
编译没有问题,将.class文件放在了jdk1.4\bin下
然后java JSplash (或者java -classpath . JSplash)
都提示如下错误:
Exception in thread "main" java.lang.NoSuchMethodError:main
不知道是哪里出错,请大家帮忙看看,谢谢了!