简体   繁体   English

在没有HTML,没有浏览器且没有Appletviewer的情况下查看Java Applet?

[英]View Java Applet without html and without browser and without Appletviewer?

With Swing applications I can use an external class to instantiate and view them. 使用Swing应用程序,我可以使用一个外部类来实例化和查看它们。

I'd like to do the same with an Applet, outside of Eclipse, without using the appletviewer. 我想在Eclipse之外对Applet进行相同的操作,而不使用appletviewer。

I want to be able to Run a class MyappletRunner and have its main method kick off the following applet for viewing. 我希望能够运行类MyappletRunner并使其main方法启动以下applet进行查看。

Given the following source code: 给出以下源代码:

import java.applet.*;
import java.awt.*;
public class Myapplet extends Applet{
  String str;
  public void init(){
    str = "This is my first applet";
  }
  public void paint(Graphics g){
    g.drawString(str, 50,50);
  }
}

The basic idea is to create your own Swing Frame , add the Applet to your frame, and then pass your Applet an instance of the AppletStub interface. 基本思想是创建自己的Swing Frame ,将Applet添加到框架,然后将Applet传递给AppletStub接口的实例。

The best example of it appears to be here: http://www.java2s.com/Code/JavaAPI/java.applet/implementsAppletStub.htm 最好的例子似乎在这里: http : //www.java2s.com/Code/JavaAPI/java.applet/implementsAppletStub.htm

Appletviewer is the tool you want (if you are just testing that is): http://download.oracle.com/javase/1.3/docs/tooldocs/win32/appletviewer.html Appletviewer是您想要的工具(如果只是进行测试): http : //download.oracle.com/javase/1.3/docs/tooldocs/win32/appletviewer.html

If you want to launch it as a standalone app, the following tutorial works: http://java.sun.com/developer/technicalArticles/Programming/TurningAnApplet/ 如果要作为独立应用程序启动,请使用以下教程: http : //java.sun.com/developer/technicalArticles/Programming/TurningAnApplet/

Not exactly sure why you are trying to do this... what exactly are you going to accomplish by doing this? 不完全确定为什么要尝试执行此操作…通过此操作您将完成什么操作? You say you want to run a java applet... within a java application... AFAIK, it isn't possible anyway. 您说要在Java应用程序中运行Java小程序... AFAIK,无论如何,这是不可能的。 If you just want to view the applet, use appletviewer. 如果只想查看小程序,请使用appletviewer。

write the folloing code in the begining of the xyz.java file: 在xyz.java文件的开头写入以下代码:

/*<applet code="xyz.class" height=30 width=50></applet>*/

Save and compile the xyz.java file. 保存并编译xyz.java文件。

Now, Execute the file using the appletviewer as following: 现在,使用appletviewer执行文件,如下所示:

c:\jdk\bin>appletviewer xyz.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM