JApplet 未运行:<未找到主要类 > [英] JApplet not running: < No main classes found >

查看:25
本文介绍了JApplet 未运行:<未找到主要类 >的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当 DrawOvalInputs.html 运行并调用 DrawOvalInputs 的类文件时,我的 JApplet 产生错误.到目前为止,我只能让它作为一个实际的应用程序运行(这就是为什么 main 在块引用中).

我对这个程序的目标是能够运行 .html 文件以在 java 控制台上以中等安全设置启动 JApplet,但无论我做什么,它都无法运行.

在来到这里之前,我已经浏览了很多页面并进行了搜索.很遗憾,我就是想不通这个 JApplet,所以如果有人能指导我朝正确的方向发展,我将不胜感激!

我的代码如下:

DrawOvalInputs.java

package drawovalapplet;导入 java.awt.BorderLayout;导入 java.awt.Frame;导入 java.awt.Graphics;导入 javax.swing.JApplet;导入 javax.swing.JOptionPane;/*** 这个小程序输入多个值,然后计算* 具有这些给定值的椭圆.** @author [已编辑]* @version 2014-05-02, [已编辑]*/公共类 DrawOvalInputs 扩展了 JApplet{私有静态 int x;//椭圆的左边缘私有静态 int y;//椭圆的上边缘私有静态整数宽度;//椭圆的宽度私有静态整数高度;//椭圆的高度私有静态 int windowWidth;//持有必要的窗口宽度.私有静态 int windowHeight;//保持窗口的必要高度.私有静态 int windowBox;//持有窗口的框形式.@覆盖公共无效初始化(){尝试{/** 收集输入值.*/输入.inputAll();/** 为盒子创建尺寸 */窗口宽度 = 宽度 + x + 50;窗口高度 = 高度 + y + 50;/*** If... else... 函数收集数据以创建* 椭圆形配件盒*/如果(窗口宽度 > 窗口高度)窗口框 = 窗口宽度;别的窗口框 = 窗口高度;} catch (Input.CanceledException ex) {System.exit(1);}}@覆盖公共空心漆(图文g){super.paint(g);g.drawOval(x, y, 宽度, 高度);}//结束方法痛苦/*** 主要入口点.* <p>执行:* <pre>java drawovalapplet.DrawOvalInputs</pre>** @param args 未使用.*//*public static void main(String args[]){Frame frame = new Frame("DrawOvalInputs");DrawOvalInputs drawOval = new DrawOvalInputs();drawOval.init();drawOval.start();frame.add(drawOval);frame.setSize(drawOval.windowBox, drawOval.windowBox);frame.setVisible(true);}*///------------------------------- 嵌套类 --------------------------------/*** 枚举输入值的名称和值.*/私人枚举输入{/*** 输入 x 坐标的消息.*/XVALUE("输入要绘制的椭圆左上角x坐标的参数:"),/*** 输入 y 坐标的消息.*/YVALUE("请输入要绘制的椭圆左上角y坐标的参数:"),/*** 输入宽度的消息.*/WIDTHVALUE("请输入要绘制的椭圆的所需宽度:"),/*** 输入高度的消息.*/HEIGHTVALUE("请输入所需的椭圆高度:");/*** 在消息中使用的字符串(来自构造函数).*/受保护的字符串邀请;/*** 用于错误消息的字符串.*/protected String error = "不是整数值——请重新输入:";/*** 此 {@literal } 的值.*/受保护的整数值;/*** @param 标签字符串在消息中使用*/输入(字符串邀请){this.invitation = 邀请;}public static void inputAll() 抛出 CanceledException{/* 确定当前正在使用哪个输入值.*/整数计数 = 0;/* 收集输入数字.*/for(输入输入:Input.values()){/* 设置邀请输入每个号码.*/字符串消息 = input.invitation;/* 循环直到用户输入一个可接受的格式数字.*/while(true)//重复环境{字符串响应;/* 从 JOptionPane 返回 Null 表示按下了 CANCEL.*/if( (response = JOptionPane.showInputDialog(message)) == null)抛出新的 CanceledException();消息 = input.error;//以防万一尝试{input.value = Integer.parseInt(response);休息;//获取值成功}catch(NumberFormatException nfe) {}//忽略所有,然后重试}计数++;如果(计数== 1)x = 输入值;否则如果(计数== 2)y = 输入值;否则如果(计数== 3)宽度 = 输入值;否则如果(计数== 4)高度 = 输入值;别的System.out.println("错误,修改.");}}@SuppressWarnings("串行")公共静态类CanceledException 扩展异常{}}}

DrawOvalInputs.html我已经使用 DrawOvalInputs.java 和下面的,以及 .class 来运行它.

<身体><小程序代码=drawovalapplet.DrawOvalInputs.java width=400 height=400></小程序>

谢谢!

解决方案

你必须用正确的路径调用它

如果你的路径是这样的

DrawOvalApplet\build\classes\drawovalapplet\DrawOvalInputs.class

你的 .html 在

DrawOvalApplet\build\DrawOvalInputs.html

叫它

<代码> ...<小程序代码=classes.drawovalapplet.DrawOvalInputs.class width=400 height=400></小程序>...

好多了你的.html在

DrawOvalApplet\build\classes\DrawOvalInputs.html

叫它

<代码> ...<小程序代码=drawovalapplet.DrawOvalInputs.class width=400 height=400></小程序>...

结果:

小程序运行

您可以调用 htmlconverter 来为您完成

java -jar htmlconverter.jar -gui

结果 DrawOvalInputs.html

<身体><!--"CONVERTED_APPLET"--><!-- HTML 转换器 --><对象classid = "clsid:CAFEEFAC-0017-0000-0051-ABCDEFFEDCBA"代码库 = "http://java.sun.com/update/1.7.0/jinstall-7u51-windows-i586.cab#Version=7,0,510,13"宽度 = 400 高度 = 400 ><参数名称 = 代码值 = drawovalapplet.DrawOvalInputs.class ><param name = "type" value = "application/x-java-applet;jpi-version=1.7.0_51"><param name = "scriptable" value = "false"><评论><嵌入type = "application/x-java-applet;jpi-version=1.7.0_51" \CODE = drawovalapplet.DrawOvalInputs.class \宽度 = 400 \高度 = 400脚本化=假pluginspage = "http://java.sun.com/products/plugin/index.html#download"><无嵌入></noembed></嵌入></评论></对象><!--<APPLET CODE = drawovalapplet.DrawOvalInputs.class WIDTH = 400 HEIGHT = 400></小程序>--><!--END_CONVERTED_APPLET"-->

My JApplet is producing a error when DrawOvalInputs.html runs and calls the class file of DrawOvalInputs. So far, I have only been able to get it work as an actual application (Which is why the main is in a block quote).

My goal for this program is to be able to run a .html file to start up the JApplet with a medium security setting on the java console, yet no matter what I've done it simply won't function.

I have looked around on quite a few pages and searches before coming here. Regrettably, I just can't figure this JApplet out, so if someone could guide me in the right direction I'd be most thankful!

My Code below:

DrawOvalInputs.java

package drawovalapplet;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JOptionPane;

/**
 * This applet inputs a number of values, and then computes the size of
 * an oval with those given values. 
 *
 * @author  [Redacted]
 * @version 2014-05-02, [Redacted]
 */
public class DrawOvalInputs extends JApplet
{
    private static int x;               //left edge of the oval
    private static int y;               //top edge of the oval
    private static int width;           //width of oval
    private static int height;          //height of oval
    private static int windowWidth;     //Holds necessary width of window.
    private static int windowHeight;    //Holds necessary height of window.
    private static int windowBox;       //Holds box form of window.


@Override
public void init()
{    
    try 
    {
        /** Collect the input values. */    
        Input.inputAll();

        /** creates dimensions for box */
        windowWidth = width + x + 50;
        windowHeight = height + y + 50;

        /** 
         * If... else... function to gather data to create
         * a fitting box for the oval
         */
        if(windowWidth > windowHeight)
            windowBox = windowWidth;
        else
            windowBox = windowHeight;

    } catch (Input.CanceledException ex) {
        System.exit(1);
    }
} 

@Override
public void paint(Graphics g)
{
    super.paint(g);      
    g.drawOval(x, y, width, height);
} // end method pain


/**
 * Main entry point.
 * <p> Execute:
 * <pre>java drawovalapplet.DrawOvalInputs</pre>
 *
 * @param args not used.
 */
/*public static void main(String args[])
{
Frame frame = new Frame("DrawOvalInputs");
DrawOvalInputs drawOval = new DrawOvalInputs();
drawOval.init();
drawOval.start();
frame.add(drawOval);
frame.setSize(drawOval.windowBox, drawOval.windowBox);
frame.setVisible(true);
}*/

//------------------------------- Nested Classes --------------------------------

/**
 * Enumeration of the name and value of the input values.
 */
private enum Input
{
/**
 * Message for the entering the x coordinate.
 */
XVALUE("Enter the argument for the x coordinate of the upper left corner of the oval to be drawn:"),

/**
 * Message for the entering the y coordinate.
 */
YVALUE("Enter the argument for the y coordinate of the upper left corner of the oval to be drawn:"),

/**
 * Message for entering the width.
 */
WIDTHVALUE("Enter the desired width of the oval to be drawn:"),

/**
 * Message for entering the height.
 */
HEIGHTVALUE("Enter the desired height of the oval:");

/**
 * String to use in messages (from the constructor).
 */
protected String invitation;

/**
 * String to use for error messages.
 */
protected String error = "Not an integer value--please re-enter:";

/**
 * Value of this {@literal <variable>}.
 */
protected int value;

/**
 * @param label string to use in messages
 */
Input(String invitation)
{
    this.invitation = invitation;
}

public static void inputAll() throws CanceledException
{
    /* Decide which input value is currently being used. */
    int count = 0; 

    /* Collect the input numbers. */
    for(Input input : Input.values())
    {
        /* Set up the invitation to enter each number. */
        String message = input.invitation;

        /* Loop until the user inputs an acceptably formatted number. */
        while(true)                         // repetition environment
        {
            String response;
            /* Null return from the JOptionPane indicates CANCEL was pressed. */
            if( (response = JOptionPane.showInputDialog(message)) == null)
                throw new CanceledException();
            message = input.error;              // just in case
            try
            {
                input.value = Integer.parseInt(response);
                break;                          // success in acquiring value
            }
            catch(NumberFormatException nfe) {}// ignore all, and try again
        }
        count++;
        if(count == 1)
            x = input.value;
        else if(count == 2)
            y = input.value;
        else if (count == 3)
            width = input.value;
        else if (count == 4)
            height = input.value;
        else
            System.out.println("Error. Revise.");   
    }
}

@SuppressWarnings("serial")
public static class CanceledException extends Exception {}
}
}

DrawOvalInputs.html I've run this with DrawOvalInputs.java and the one below, as well as with .class instead.

<html>
  <body>
      <applet code=drawovalapplet.DrawOvalInputs.java width=400 height=400>
      </applet>
  </body>
</html>

Thanks!

解决方案

you must call it with the right path

if your path is like

DrawOvalApplet\build\classes\drawovalapplet\DrawOvalInputs.class

and your .html is in

DrawOvalApplet\build\DrawOvalInputs.html

call it

 ...
      <applet code=classes.drawovalapplet.DrawOvalInputs.class width=400 height=400>
      </applet>
 ...

much better your .html is in

DrawOvalApplet\build\classes\DrawOvalInputs.html

call it

 ...
      <applet code=drawovalapplet.DrawOvalInputs.class width=400 height=400>
      </applet>
 ...

result :

applet running

You can call htmlconverter and let do it for you

java -jar htmlconverter.jar -gui

Result DrawOvalInputs.html

<html>
  <body>
      <!--"CONVERTED_APPLET"-->
<!-- HTML CONVERTER -->
<object
    classid = "clsid:CAFEEFAC-0017-0000-0051-ABCDEFFEDCBA"
    codebase = "http://java.sun.com/update/1.7.0/jinstall-7u51-windows-i586.cab#Version=7,0,510,13"
    WIDTH = 400 HEIGHT = 400 >
    <PARAM NAME = CODE VALUE = drawovalapplet.DrawOvalInputs.class >
    <param name = "type" value = "application/x-java-applet;jpi-version=1.7.0_51">
    <param name = "scriptable" value = "false">

    <comment>
    <embed
            type = "application/x-java-applet;jpi-version=1.7.0_51" \
            CODE = drawovalapplet.DrawOvalInputs.class \
            WIDTH = 400 \
            HEIGHT = 400
        scriptable = false
        pluginspage = "http://java.sun.com/products/plugin/index.html#download">
        <noembed>

            </noembed>
    </embed>
    </comment>
</object>

<!--
<APPLET CODE = drawovalapplet.DrawOvalInputs.class WIDTH = 400 HEIGHT = 400>


</APPLET>
-->
<!--"END_CONVERTED_APPLET"-->

  </body>
</html>

这篇关于JApplet 未运行:&lt;未找到主要类 >的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆