我是初学者,一个很奇怪的问题,请教大家~~

sun4flower 2003-07-02 10:36:43
我下载了一个关于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

不知道是哪里出错,请大家帮忙看看,谢谢了!

...全文
46 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sun4flower 2003-07-02
  • 打赏
  • 举报
回复
啊,我知道了,这是一个类,不可以单独运行~谢谢大家~

哪位大虾可以帮我写完整的main程序,将这个效果运行出来呢~~~再次谢谢了~
pingfan520 2003-07-02
  • 打赏
  • 举报
回复
少了main()啊
tomtian 2003-07-02
  • 打赏
  • 举报
回复
楼上的兄弟,你没有main函数怎么能跑呢
火云洞红孩儿 2003-07-02
  • 打赏
  • 举报
回复
少了public static main()
cctvnet 2003-07-02
  • 打赏
  • 举报
回复

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();
}
public static void main(String[] args)
{
System.out.println("你 少 了 main 函数");
}
}
geyf 2003-07-02
  • 打赏
  • 举报
回复
这个只是一个类而已,不知直接可以看出来的
需要有main方法的才行啊

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧