本文介绍了JApplet的不运行:LT;发现&GT无主班;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在DrawOvalInputs.html运行并调用DrawOvalInputs的类文件我JApplet的是产生错误。到目前为止,我只能够把它作为一个实际应用的工作​​(这就是为什么主要是在一个块引号)。

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).

我对这一计划的目标是能够运行一个.html文件来启动JApplet的与Java控制台上的中等安全设置,但无论我做了什么它根本不起作用。

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.

我已经来这里之前看了看周围的好几个页面和搜索。遗憾的是,我实在不明白这个JApplet的出来,所以,如果有人可以指导我在正确的方向,我会最想感谢!

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!

我的code以下:

DrawOvalInputs.java

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
我曾与DrawOvalInputs.java和如下的运行它,以及与替代的.class

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>

谢谢!

推荐答案

您必须用正确的道路称之为

you must call it with the right path

如果您的路径是像

DrawOvalApplet\build\classes\drawovalapplet\DrawOvalInputs.class

和您的.html是

DrawOvalApplet\build\DrawOvalInputs.html

称之为

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

更好您的.html是

DrawOvalApplet\build\classes\DrawOvalInputs.html

称之为

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

结果:

小程序运行

您可以致电 htmlconverter ,让为你做它

You can call htmlconverter and let do it for you

java -jar htmlconverter.jar -gui

结果 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;发现&GT无主班;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 18:40