applet 放在html中的问题,急

seaman390302602 2009-04-01 03:57:14
做一个视频播放的applet ,用到了jmf。在eclipse下可以运行,但是放在用appletviewer来运行.html的时候就提示无法实例化类。



代码如下:
import javax.media.*;
//import javax.media.format.*;
//import javax.media.protocol.*;
import java.awt.*;
import java.awt.event.*;
//import java.applet.*;

/**
* <p>
* Title:
* </p>
* <p>
* Description:
* </p>
* <p>
* Copyright: Copyright (c) 2004
* </p>
* <p>
* Company:
* </p>
*
* @author not attributable
* @version 1.0
*/

public class VideoPlayer1 extends Frame implements ControllerListener,
ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;

Player videoPlayer;

String filename;

/** creates new VideoPlayer1 */
public VideoPlayer1(String s1) {
super(s1);

// handler window event handler
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});

// create the menu
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu fileMenu = new Menu("File");
mb.add(fileMenu);

MenuItem itemPlay = new MenuItem("Play");
itemPlay.addActionListener(this);
fileMenu.add(itemPlay);

MenuItem itemStop = new MenuItem("Stop");
itemStop.addActionListener(this);
fileMenu.add(itemStop);

MenuItem itemExit = new MenuItem("Exit");
itemExit.addActionListener(this);
fileMenu.add(itemExit);
this.validate();
this.setVisible(true);
}

// add the event handler

public void actionPerformed(ActionEvent e) {
String action = e.getActionCommand().toString();
if (action.equals("Play")) {
play();
}
if (action.equals("Stop")) {
stop();
}
if (action.equals("Exit")) {
dispose();
System.exit(0);
}

}

private void stop() {
if (videoPlayer != null) {
videoPlayer.stop();
}
}

private void play() {
try {
FileDialog fd = new FileDialog(this, "Choose Video",
FileDialog.LOAD);
fd.setVisible(true);
//fd.show();

// assemble the filename
filename = fd.getDirectory() + fd.getFile();

// create the player
videoPlayer = Manager.createPlayer(new MediaLocator("file:///"
+ filename));
// add a listener for player state changes
videoPlayer.addControllerListener(this);

videoPlayer.start();
} catch (Exception e) {
System.out.println("Error" + e);
}
}// end play function

public synchronized void controllerUpdate(ControllerEvent event) {
System.out.println("Event: " + event);

if (event instanceof RealizeCompleteEvent) {
Component comp;

if ((comp = videoPlayer.getVisualComponent()) != null) {
add("Center", comp);
} else {
System.out.println("Unable to get visual component");
}

if ((comp = videoPlayer.getControlPanelComponent()) != null) {
add("South", comp);
}

validate();
}
}

public static void main(String[] args) {
VideoPlayer1 vp1 = new VideoPlayer1("videoPlayer1");

// show the frame containing the video
vp1.setSize(300, 300);
vp1.setLocation(250, 300);
}

}




html 的代码:



<HTML>

<BODY>

<!--"CONVERTED_APPLET"-->
<!-- HTML CONVERTER -->
<object classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="300" height="300" codebase = "http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=5,0,0,5" >
<PARAM NAME = CODE VALUE = "VideoPlayer1.class" >
<PARAM NAME = CODEBASE VALUE = "." >
<PARAM NAME = ARCHIVE VALUE = "VideoPlayer1.jar" >
<param name = "type" value = "application/x-java-applet;version=1.5">
<param name = "scriptable" value = "false">
<comment> <embed width="300" height="300" type = "application/x-java-applet;version=1.5" CODE = "VideoPlayer1.class" JAVA_CODEBASE = "."
ARCHIVE = "VideoPlayer1.jar"
scriptable = false
pluginspage = "http://java.sun.com/products/plugin/index.html#download">
<noembed> </noembed> </embed>
</comment>
</object>


</BODY>

</HTML>



F:\software\tools\eclipse-SDK-3.2.1-win32\eclipse\workplace\E-net>appletviewer V
ideoPlayer1.html
载入:无法实例化 VideoPlayer1.class。
java.lang.InstantiationException: VideoPlayer1
at java.lang.Class.newInstance0(Class.java:335)
at java.lang.Class.newInstance(Class.java:303)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:712)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:641)
at sun.applet.AppletPanel.run(AppletPanel.java:320)
at java.lang.Thread.run(Thread.java:595)


因为VideoPlayer1.java编译出两个class VideoPlayer1.class和VideoPlayer1$1.class,我将两个class 打包成VideoPlayer1.jar
不知道问题出在哪里,请大虾帮忙指点一下~

...全文
13 点赞 收藏 回复
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复

还没有回复,快来抢沙发~

相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2009-04-01 03:57
社区公告
暂无公告