我的JApplet在DrawOvalInputs时产生错误。html运行并调用DrawOvalInputs的类文件。到目前为止,我只能将其作为一个实际应用程序使用(这就是为什么main在块引用中)。
我对这个程序的目标是能够在 java 控制台上运行一个.html文件以中等安全设置启动 JApplet,但无论我做什么,它都无法运行。
在来这里之前,我已经浏览了相当多的网页和搜索。遗憾的是,我就是想不通这个贾普雷特,所以如果有人能给我指引正确的方向,我会非常感激!
我的代码如下:
绘制椭圆输入.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运行了这个。
<html>
<body>
<applet code=drawovalapplet.DrawOvalInputs.java width=400 height=400>
</applet>
</body>
</html>
谢谢
使用类文件和实际文件路径和名称。例如:
<applet code=DrawOvalInputs.class width=400 height=400>
</applet>
如果类文件与超文本标记语言文件位于同一文件夹中。
你必须用正确的道路来称呼它
如果你的路径是这样的
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>
...
结果:
小程序运行
您可以调用html的转换器
,让它为你做
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,基本上这个小程序将允许用户绘制一个二次方程图,并插入x轴和y轴的范围。但要达到这一点,还有很多工作要做。 我还在设计界面的阶段。 以下是我的代码:
问题内容: 我通过键入crontab -e在ubuntu环境中为root用户设置了cronjob 但是cronjon不会运行。我已经尝试检查cronjob是否正在使用 pgrep cron 并给出了进程ID3033。shell脚本调用了python文件,并用于发送电子邮件。可以运行python文件。没有错误,但cron不运行。daily.sh文件中包含以下代码。 问题答案: WTF ?! 我的cr
问题内容: 我想将JApplet转换为JFrame。我在互联网上找到了一个单词搜索游戏的代码。我想在一个类的演示中使用此代码。但我不想在applet中使用它。我要在此处粘贴的代码大约有7,000个字符。我尝试使用JApplet并扩展JFrame,然后将所有用于初始化的代码放入构造函数(零自变量构造函数)中。这导致大约十个我无法解决的错误。我想制作一个单词搜索游戏,并且找到了一个很好的例子,但是我无
问题内容: 我有几个服务器: Jenkins Gitlab 在gitlab上,我有一个webhook: 在詹金斯身上,我有一份工作: 源代码管理: Git: gitlab) 凭证:密钥对有效 要建立的分支:* / master 仓库浏览器:gitlab 版本:6.5.1 轮询SCM 有什么线索为什么詹金斯不能胜任这份工作? 问题答案: 在Jenkins上,您应禁用并将其设置为(not )
我正在使用Netbeans 7.4。我使用glassfish服务器创建了一个新的web项目。现在我喜欢在其中使用groovy脚本。但问题是groovy代码没有在那里进行解释。其输出与代码相同。 它应该给输出Hello Barun!但不是给我输出def name='Barun'println“Hello$name!” 我还将最新的groovy-all jar文件包含到我的项目库中。但是还没有运气。我
问题内容: 我现在正在编写一个JApplet,每当我调用super.paint()时,该applet都会闪烁。我正在使用双缓冲(先绘制图像,然后渲染该图像),但我认为super.paint()正在清除屏幕或其他东西,打败了我的双缓冲。 我知道我应该使用paintComponents(),但是由于某些原因,当我调用“ currentScreen.Draw(g)”时,它不会显示屏幕的绘制。 谁能帮我这