JApplet未运行:

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

我的这个程序的目标是能够运行.html文件来启动JSPlet,在Java控制台上使用中等安全设置,但无论我做了什么,它都无法正常运行。

在来到这里之前,我已经浏览了很多页面和搜索。 遗憾的是,我无法想象这个JApplet,所以如果有人能指导我朝着正确的方向前进,我会非常感激!

我的代码如下:

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

Execute: *

java drawovalapplet.DrawOvalInputs

* * @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 }. */ 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来运行它。

       

谢谢!

你必须用正确的道路来呼唤它

如果你的道路是这样的

 DrawOvalApplet\build\classes\drawovalapplet\DrawOvalInputs.class 

你的.html就在

 DrawOvalApplet\build\DrawOvalInputs.html 

叫它

  ...   ... 

你的.html 好多

 DrawOvalApplet\build\classes\DrawOvalInputs.html 

叫它

  ...   ... 

结果:

在此处输入图像描述

小程序运行

在此处输入图像描述

您可以调用htmlconverter并让它为您完成

 java -jar htmlconverter.jar -gui 

在此处输入图像描述

结果DrawOvalInputs.html

                    

使用类文件和实际文件路径和名称。 例如:

    

如果类文件与HTML文件位于同一文件夹中。