gpt4 book ai didi

java - BlueJ 中的 Appletviewer 无法启动

转载 作者:行者123 更新时间:2023-12-01 15:10:11 25 4
gpt4 key购买 nike

因此,我像往常一样运行一个小程序,在左下角显示“在 appletviewer 中执行小程序”时,它会保留在那里,而 appletviewer 永远不会打开。当我右键单击该类时,“运行小程序”呈红色(如果这很重要的话)。我已经卸载了计算机上与 Java 相关的所有内容,并多次重新安装了 JDK 7 以及 BlueJ,但仍然得到 appletviewer 未弹出的结果。我一直尝试的小程序类是直接来 self 的教科书网站的,所以我猜代码没有任何问题。该小程序与我学校其他人的计算机运行良好。那么我该怎么做才能让 appletviewer 工作呢?

这是该类的代码:

import javax.swing.JApplet;
import java.awt.*;

public class Snowman extends JApplet
{
public void paint (Graphics page)
{
final int MID = 150;
final int TOP = 50;

setBackground (Color.cyan);

page.setColor (Color.blue);
page.fillRect (0, 175, 300, 50); // ground

page.setColor (Color.yellow);
page.fillOval (-40, -40, 80, 80); // sun

page.setColor (Color.white);
page.fillOval (MID-20, TOP, 40, 40); // head
page.fillOval (MID-35, TOP+35, 70, 50); // upper torso
page.fillOval (MID-50, TOP+80, 100, 60); // lower torso

page.setColor (Color.black);
page.fillOval (MID-10, TOP+10, 5, 5); // left eye
page.fillOval (MID+5, TOP+10, 5, 5); // right eye

page.drawArc (MID-10, TOP+20, 20, 10, 190, 160); // smile

page.drawLine (MID-25, TOP+60, MID-50, TOP+40); // left arm
page.drawLine (MID+25, TOP+60, MID+55, TOP+60); // right arm

page.drawLine (MID-20, TOP+5, MID+20, TOP+5); // brim of hat
page.fillRect (MID-15, TOP-20, 30, 25); // top of hat
}
}

最佳答案

确保在运行之前导入小程序类。这可能与你的问题有关。导入 java.applet.;导入 java.awt.;

关于java - BlueJ 中的 Appletviewer 无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12432927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com