Java 开始:小程序未初始化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22956559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 19:37:30  来源:igfitidea点击:

Start: Applet is not initialized

javadebuggingapplet

提问by user3461957

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 时,我得到以下信息:

enter image description here

在此处输入图片说明

String is not being displayed rather "Start: applet is not initialized."

未显示字符串,而是“开始:小程序未初始化”。

回答by JGeo

code = "FirstJaveApplet.class": Javanot Jave

code = "FirstJaveApplet.class":Java不是Jave

回答by Nambi

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;

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


}

回答by Andrew Thompson

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

The codeattribute value should be the Fully Qualified Class name as opposed to the applet file name. So that should read:

code属性值应该是相对于小程序的文件名完全限定类名。所以应该是:

<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. Unless the class is present in the right place, the problem will continue.

请注意,JRE 将在名为 .html 的 HTML 目录的子目录中搜索该类firstjavaapplet。除非班级出现在正确的位置,否则问题将继续存在。

回答by ArunDhwaj IIITH

In the case of PApplet. On MacOS 10.10You need to change the the JRE System Librarymin to 1.7.

在 PApplet 的情况下。On MacOS 10.10您需要将JRE System Librarymin更改为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.

希望它对你有帮助。

回答by user2944122

  • For PApplet
  • On Mac
  • Usually happens with JRE 1.6
  • 对于 PApplet
  • 在 Mac 上
  • 通常发生在 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(如果已安装,它将显示)通过右键单击并选择正确的选项从构建路径中删除旧的

回答by Abhi

Try after placing the above java file,in a folder with name firstjavaapplet(pakage name) in the source pakagefolder.

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

回答by satyaprakash

Don't name your HTML file same as the Class File I think that will work.

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

回答by Zeba Nasrin

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

回答by Dwaita Acharya

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();

    }
}

回答by Anil Kushwaha

No Need to write the main method in appletand you have to extend Applet than your applet will run

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

public class FirstJavaApplet extends Applet