简体   繁体   English

开始:小程序未初始化

[英]Start: Applet is not initialized

I am beginner to Applets.我是小程序的初学者。 Here is code for a basic applet to display string.这是用于显示字符串的基本小程序的代码。

package firstjavaapplet;

import java.awt.Graphics; // program uses class Graphics

import javax.swing.JApplet; // program uses class JApplet

public class FirstJavaApplet extends JApplet
{

    // draw text on applet’s background

    @Override
    public void paint( Graphics g )
    {
        // call superclass version of method paint
        super.paint( g );
        // draw a String at x-coordinate 25 and y-coordinate 25
        g.drawString( "Welcome to Java Programming!", 25, 25 );
    } // end method paint

    public static void main(String[] args)
    {
        FirstJavaApplet obj = new FirstJavaApplet();

    }
}

Following is HTML file I am using to include applet in webpage.以下是我用来在网页中包含小程序的 HTML 文件。

<body>

<applet code = "FirstJaveApplet.class" width = "300" height = "300">
</applet>

</body>

</html>

When I run Applet in appletviewer FirstJaveApplet.html, I get following:当我在 appletviewer FirstJaveApplet.html 中运行 Applet 时,我得到以下信息:

在此处输入图像描述

String is not being displayed rather "Start: applet is not initialized."没有显示字符串,而是显示“开始:小程序未初始化”。

<applet code = "FirstJaveApplet.class" width = "300" height = "300">
</applet>

The code attribute value should be the Fully Qualified Class name as opposed to the applet file name. code属性值应该是完全限定的类名,而不是小程序文件名。 So that should read:所以应该是:

<applet code = "firstjavaapplet.FirstJavaApplet" width = "300" height = "300">
</applet>

Note that the JRE will search for the class in a sub-directory of the HTML directory named firstjavaapplet .请注意,JRE 将在名为firstjavaapplet的 HTML 目录的子目录中搜索firstjavaapplet Unless the class is present in the right place, the problem will continue.除非班级出现在正确的位置,否则问题将继续存在。

code = "FirstJaveApplet.class" Java不是Jave

I was also facing the same issue and none of the forum's solution rescued me :(我也面临同样的问题,论坛的解决方案都没有救我:(

Then I realized, we need the set the size and visibility of the applet.然后我意识到,我们需要设置小程序的大小和可见性。 You can include the following constructor as your code:您可以包含以下构造函数作为您的代码:

FirstJavaApplet()
{
    setSize(500, 500);
    setVisible(true);
}

Applet don't need a main method to start Applet 不需要 main 方法来启动

Just run without main method无需main方法即可运行

I think you having the problem with your package name我认为你的包名有问题

compile without the package name package firstjavaapplet;不带包名package firstjavaapplet;编译package firstjavaapplet;

public class FirstJavaApplet extends JApplet
{


    @Override
    public void paint( Graphics g )
    {
        // call superclass version of method paint
        super.paint( g );
        // draw a String at x-coordinate 25 and y-coordinate 25
        g.drawString( "Welcome to Java Programming!", 25, 25 );
    } // end method paint


}

In the case of PApplet.在 PApplet 的情况下。 On MacOS 10.10 You need to change the the JRE System Library min to 1.7 . On MacOS 10.10您需要将JRE System Library min 更改为1.7

In my case java.lang.UnsupportedClassVersionError: processing/core/PApplet : Unsupported major.minor version 51.0在我的情况下java.lang.UnsupportedClassVersionError: processing/core/PApplet : Unsupported major.minor version 51.0

Its throwing above.它在上面投掷。 Its resolved when I'd set .JRE System Library-1.7当我设置.JRE System Library-1.7时它解决了

Hope its help you.希望它对你有帮助。

  • For PApplet对于 PApplet
  • On Mac在 Mac 上
  • Usually happens with JRE 1.6通常发生在 JRE 1.6

Change the Build path as:将构建路径更改为:

On your Project JRE system Library > Build Path> Configure Build path Choose JRE 1.7 or 1.8 (if installed it will be displayed) Remove the old one from build path by right-clicking and choosing the right option在您的项目 JRE 系统库 > 构建路径 > 配置构建路径选择 JRE 1.7 或 1.8(如果已安装,它将显示)通过右键单击并选择正确的选项从构建路径中删除旧的

将上述java文件放在源pakagefolder中名为firstjavaapplet(pakage name)的文件夹中后尝试。

不要将您的 HTML 文件命名为我认为会起作用的类文件。

Write the HTML code as below:编写 HTML 代码如下:

<html>
  <body>
    <applet code="firstjavaapplet.FirstJavaApplet" width ="300" height ="300">
    </applet>
  </body>
</html>

Save it as: FirstJavaApplet.html另存为: FirstJavaApplet.html

Compile your Java Source File as:将您的 Java 源文件编译为:

javac -d . FirstJavaApplet.java 

(You might have skipped compiling your Java Source File) (您可能跳过了编译 Java 源文件)

Then run your HTML file as:然后运行你的 HTML 文件:

appletviewer FirstJavaApplet.html

no need to create html file.whatever line you write in html also write in java after import statement无需创建 html 文件。你在 html 中写的任何行也在 import 语句后用 java 写

 import java.awt.Graphics; // program uses class Graphics import javax.swing.JApplet; // program uses class JApplet /*<applet code = "FirstJaveApplet.class" width = "300" height = "300"> </applet>*/ public class FirstJavaApplet extends JApplet { // draw text on applet's background @Override public void paint( Graphics g ) { // call superclass version of method paint super.paint( g ); // draw a String at x-coordinate 25 and y-coordinate 25 g.drawString( "Welcome to Java Programming!", 25, 25 ); } // end method paint public static void main(String[] args) { FirstJavaApplet obj = new FirstJavaApplet(); } }

无需在小程序中编写 main 方法,并且您必须扩展小程序才能运行小程序

public class FirstJavaApplet extends Applet

I was also facing same problem because, i have changed path during installation of Older JDK (jdk 10.0.2) to D Drive .我也遇到了同样的问题,因为在将旧 JDK (jdk 10.0.2)安装到D Drive期间,我更改了路径。 By doing this what happen is your main jdk-10.0.2 folder will install in C Drive's ProgramFiles folder and only copy of bin and some other folder is created in you newly mentioned path during installation.通过这样做,您的主jdk-10.0.2文件夹将安装在 C Drive 的ProgramFiles文件夹中,并且在安装过程中在您新提到的路径中仅创建 bin 和其他一些文件夹的副本。

So What You Can do is所以你能做的是

  1. Go to C Drive > Programfiles > java . Go 到C Drive > java文件> Programfiles
  2. Cut Whole jdk-10.0.2 (or older whichever yo have downloaded) and paste it wherever you want.剪切整个jdk-10.0.2 (或您下载的旧版本)并将其粘贴到您想要的任何位置。
  3. After pasting it go into jdk-10.0.2 folder -> Go to bin folder of it and write all your programs here.将 go 粘贴到jdk-10.0.2文件夹 -> Go 到它的 bin 文件夹后,并在此处编写所有程序。

i face the same, but in my case i was using jdk17 to compile and using that.class file to run on appletviewer but appletviewer is closed after jdk9 so, any.class file that was created using jdk9 or higher it can't support so, i just used jdk8 to compile my program and it run fine on that appleviewer我面临同样的情况,但在我的情况下,我使用 jdk17 编译并使用 that.class 文件在 appletviewer 上运行,但 appletviewer 在 jdk9 之后关闭,因此,使用 jdk9 或更高版本创建的 any.class 文件不支持所以,我只是使用 jdk8 来编译我的程序,它在那个 appleviewer 上运行良好

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

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