- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在网页上加载小程序,但它无法正确加载。这是该页面的小程序标签:
<applet codebase="classes" code="Simulation.class" width="600" height="600"></applet>
我已经能够毫无问题地在网站上加载其他小程序,但是这个小程序要么什么也不做,要么无法通过加载屏幕(请参阅您自己 here )。小程序需要其他类,但它们仍然都在“classes”目录下,所以我认为这不是问题。以下是Simulation.java 文件的代码:
import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.ArrayList;
public class Simulation
extends Applet
implements Runnable, MouseListener, MouseMotionListener, KeyListener{
private static final long serialVersionUID = -1914559969027349635L;
private boolean threadSuspended;
private Thread t = null;
private int startX;
private int startY;
private int endX;
private int endY;
private Environment env;
private int numAgents = -1;
private int width;
private int height;
private int stepTime;
private int currentParam;
private boolean start;
private boolean instructions;
private final double START_RANGE = 70.0;
private final double START_BUFFER = 5.0;
private int speed;
private final int[] SPEEDS = {4, 5, 6, 7, 8,
10, 12, 15, 18, 22,
26, 30, 35, 40, 50,
65, 80, 100, 150, 300};
public void init() {
start = true;
currentParam = 1;
initParams();
env = new Environment(width, height, numAgents, START_RANGE, START_BUFFER);
env.init();
resize(width, height);
setBackground(Color.WHITE);
addMouseListener(this);
addMouseMotionListener(this);
addKeyListener(this);
repaint();
}
public void restart() {
stop();
start = true;
double tempVD = env.getVelocityDiscount();
double tempHD = env.getHeadingDiscount();
env = new Environment(width, height, numAgents, env.getRange(), env.getBuffer());
env.init();
env.setVelocityDiscount(tempVD);
env.setHeadingDiscount(tempHD);
repaint();
}
private void initParams() {
start = true;
width = 600;
height = 600;
stepTime = 15;
speed = 8;
getNumAgents();
}
private void getNumAgents() {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
if (numAgents < 1) {
System.out.print("Number of agents: ");
numAgents = Integer.parseInt(reader.readLine());
}
}
catch (Exception e) {
System.err.println("Error reading input. Please enter only positive integers.");
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
System.err.println("Thread interrupted.");
System.exit(1);
}
getNumAgents();
}
if (numAgents < 1) {
System.err.println("Error reading input. Please enter only positive integers.");
getNumAgents();
}
}
public void start(){
if (t == null){
t = new Thread(this);
threadSuspended = false;
t.start();
}
else{
if(threadSuspended){
threadSuspended = false;
synchronized(this){
notify();
}
}
}
}
public void stop(){
threadSuspended = true;
}
public void run(){
numAgents = env.getAgents().size();
width = env.getWidth();
height = env.getHeight();
try {
stop();
while (true) {
if (threadSuspended){
synchronized(this){
while (threadSuspended){
wait();
}
}
}
if (this.getWidth() != env.getWidth() || this.getHeight() != env.getHeight()) {
env.setWidth(this.getWidth());
env.setHeight(this.getHeight());
}
env.cycle();
repaint();
for (int i = 0; i < stepTime / 5; i++) {
Thread.sleep(5);
}
}
}
catch (InterruptedException e) {
System.err.println("Runtime Error");
e.printStackTrace();
}
}
public void paint(Graphics g){
g.setFont(new Font("SansSerif", Font.PLAIN, 15));
ArrayList<Agent> agents = env.getAgents();
for (Agent i : agents) {
if (i.isSelected()) {
g.setColor(Color.RED);
g.fillOval((int) i.getX() - 2, (int) i.getY() - 2, 5, 5);
}
else {
switch (i.getGroup()) {
case 0:
g.setColor(Color.BLACK);
break;
case 1:
g.setColor(Color.BLUE);
break;
case 2:
g.setColor(Color.YELLOW);
break;
case 3:
g.setColor(Color.RED);
break;
case 4:
g.setColor(Color.GREEN);
break;
case 5:
g.setColor(Color.ORANGE);
break;
case 6:
g.setColor(Color.CYAN);
break;
case 7:
g.setColor(Color.PINK);
break;
case 8:
g.setColor(Color.MAGENTA);
break;
case 9:
g.setColor(Color.DARK_GRAY);
break;
}
g.drawOval((int) i.getX() - 1, (int) i.getY() - 1, 3, 3);
}
}
if (startX != -1 && startY != -1 && endX != -1 && endY != -1) {
g.setColor(Color.LIGHT_GRAY);
Rectangle r = getDraggedRect();
g.drawRect((int) r.getMinX(), (int) r.getMinY(), r.width, r.height);
}
g.setColor(Color.LIGHT_GRAY);
switch (currentParam) {
case 1:
g.drawString("Speed: " + (SPEEDS.length - speed), 2, 12);
break;
case 2:
g.drawString("Sensing range: " + env.getRange(), 2, 12);
break;
case 3:
g.drawString("Velocity discount: " + env.getVelocityDiscount(), 2, 12);
break;
case 4:
g.drawString("Heading discount: " + env.getHeadingDiscount(), 2, 12);
break;
case 5:
g.drawString("Buffer: " + env.getBuffer(), 2, 12);
break;
}
if (start || instructions) {
drawInstructions(g);
}
}
private void drawInstructions(Graphics g) {
Color c = new Color(50, 50, 50, 200);
g.setColor(c);
int startX = (width / 2) - 152;
int startY = (width / 2) - 152;
g.fill3DRect(startX, startY, 304, 304, true);
g.setColor(Color.WHITE);
g.setFont(new Font("SansSerif", Font.PLAIN, 10));
g.drawString("Please set parameters before starting (parameters can be", startX + 3, startY + 13);
g.drawString("altered at any time - current selected parameter is in the", startX + 3, startY + 26);
g.drawString("upper left corner at all times):", startX + 3, startY + 39);
g.drawString("Press 'S' to change simulation speed", startX + 3, startY + 52);
g.drawString("Press 'R' to change sensing range", startX + 3, startY + 65);
g.drawString("Press 'V' to change velocity discount", startX + 3, startY + 78);
g.drawString("Press 'H' to change header discount", startX + 3, startY + 91);
g.drawString("Press 'B' to change buffer size", startX + 3, startY + 104);
g.drawString("Use the UP and DOWN arrow keys to alter parameters", startX + 3, startY + 117);
g.drawString("Press the FORWARD arrow while paused to move one step", startX + 3, startY + 143);
g.drawString("Press SPACEBAR to pause or resume", startX + 3, startY + 156);
g.drawString("Reset the simulation by pressing ENTER", startX + 3, startY + 169);
g.drawString("Groups:", startX + 3, startY + 195);
g.drawString("Assign agents to any group by pressing 0-9 when selected.", startX + 3, startY + 208);
g.drawString("CLICK on any agent to select it, or select several agents", startX + 3, startY + 221);
g.drawString("at once by DRAGGING a selection box around them.", startX + 3, startY + 234);
g.drawString("Agents will only cohere to others in their group, but will", startX + 3, startY + 247);
g.drawString("still avoid collisions with all agents in the simulation.", startX + 3, startY + 260);
g.drawString("Press SPACEBAR to begin", startX + 3, startY + 286);
g.setFont(new Font("SansSerif", Font.ITALIC, 10));
g.drawString("NOTE: these instructions can be brought up by pressing i", startX + 3, startY + 299);
}
private Rectangle getDraggedRect() {
int xS;
int width;
int yS;
int height;
if (startX > endX) {
xS = endX;
width = startX - endX;
}
else {
xS = startX;
width = endX - startX;
}
if (startY > endY) {
yS = endY;
height = startY - endY;
}
else {
yS = startY;
height = endY - startY;
}
return new Rectangle(xS - 3, yS - 3, width + 7, height + 7);
}
private double roundTwo(double d) {
DecimalFormat twoDForm = new DecimalFormat("#.##");
return Double.valueOf(twoDForm.format(d));
}
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
stop();
startX = e.getX();
startY = e.getY();
}
public void mouseReleased(MouseEvent e) {
endX = e.getX();
endY = e.getY();
Rectangle r = getDraggedRect();
Point temp;
for (Agent i : env.getAgents()) {
temp = new Point((int) i.getX(), (int) i.getY());
if (r.contains(temp)) {
i.select();
}
else {
i.setSelected(false);
}
}
startX = -1;
startY = -1;
endX = -1;
endY = -1;
repaint();
}
public void mouseDragged(MouseEvent e) {
endX = e.getX();
endY = e.getY();
repaint();
}
public void mouseMoved(MouseEvent e) {}
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode();
switch (code) {
case 10:
restart();
break;
case 32:
start = false;
if (threadSuspended) {
start();
}
else {
stop();
}
break;
case 39:
if (threadSuspended && !start) {
env.cycle();
repaint();
}
break;
case 83:
currentParam = 1;
repaint();
break;
case 82:
currentParam = 2;
repaint();
break;
case 86:
currentParam = 3;
repaint();
break;
case 72:
currentParam = 4;
repaint();
break;
case 66:
currentParam = 5;
repaint();
break;
case 65:
env.setAllSelected();
repaint();
break;
case 73:
if (!start) {
instructions = !instructions;
repaint();
}
break;
case 48:
env.setSelectedGroup(0);
break;
case 49:
env.setSelectedGroup(1);
break;
case 50:
env.setSelectedGroup(2);
break;
case 51:
env.setSelectedGroup(3);
break;
case 52:
env.setSelectedGroup(4);
break;
case 53:
env.setSelectedGroup(5);
break;
case 54:
env.setSelectedGroup(6);
break;
case 55:
env.setSelectedGroup(7);
break;
case 56:
env.setSelectedGroup(8);
break;
case 57:
env.setSelectedGroup(9);
break;
}
switch (currentParam) {
case 1:
if (code == 38 && speed > 0) {
speed--;
stepTime = SPEEDS[speed];
repaint();
}
if (code == 40 && speed < SPEEDS.length - 1) {
speed++;
stepTime = SPEEDS[speed];
repaint();
}
break;
case 2:
if (code == 38 && env.getRange() < 200) {
env.setRange(env.getRange() + 5);
repaint();
}
if (code == 40 && env.getRange() > 5) {
env.setRange(env.getRange() - 5);
repaint();
}
break;
case 3:
if (code == 38 && env.getVelocityDiscount() < 0.99) {
env.setVelocityDiscount(roundTwo(env.getVelocityDiscount() + 0.01));
repaint();
}
if (code == 40 && env.getVelocityDiscount() > 0.00) {
env.setVelocityDiscount(roundTwo(env.getVelocityDiscount() - 0.01));
repaint();
}
break;
case 4:
if (code == 38 && env.getHeadingDiscount() < 0.99) {
env.setHeadingDiscount(roundTwo(env.getHeadingDiscount() + 0.01));
repaint();
}
if (code == 40 && env.getHeadingDiscount() > 0.01) {
env.setHeadingDiscount(roundTwo(env.getHeadingDiscount() - 0.01));
repaint();
}
break;
case 5:
if (code == 38 && env.getBuffer() < 100) {
env.setBuffer(env.getBuffer() + 5);
repaint();
}
if (code == 40 && env.getBuffer() > 0) {
env.setBuffer(env.getBuffer() - 5);
repaint();
}
break;
}
}
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {}
}
任何关于为什么无法正确加载的帮助或建议都将受到赞赏。谢谢!
最佳答案
启动 Java 控制台和小程序并观察异常。
关于Java Applet 在浏览器中加载时卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5671601/
我正在我的 xamarin.forms 应用程序中实现扫描仪功能,为此我正在使用 iOS native AVCaptureSession。但我的问题是在扫描或捕获 session 处于事件状态并且设备
所以我目前正在为我的项目制作一个音乐应用程序,它允许用户创建自己的音乐播放列表。但是,当我单击显示媒体选择器按钮时,它只显示白屏,当包含媒体选择器的 View 是 Initial View Contr
当我尝试在模拟器中启动 AVD 时,会出现一个小窗口(见图片),5 秒后它说没有响应并一直保持这种状态直到我关闭它。 我在网上搜索并尝试了所有解决方案,但都没有成功 在 BIOS 中启用了虚拟化 已安
尝试使用以下命令从视频中提取特定帧(删除了文件的特定名称!: ffmpeg -i video.mp4 -vf "select-gte(n\,6956)"-vframes 10262 文件夹/帧%d.j
我怎么知道终端正在继续工作而不中断它? 我已经运行了以下 git 命令: clone git://ligo-vcs.phys.uwm.edu/lalsuite.gituote 一段时间后它似乎被卡住了
我对 WPF 中的数据网格有一个奇怪的问题。我正在为我的应用程序使用 MVVM 模式,并且我的 View 模型实现了 idataerrorinfo 接口(interface)。每当我在添加新行后在我的
我有这个 Excel 文件,当我输入数据时它卡住了。例如,我双击一个单元格,输入数据,然后按“输入”。它会卡住而不是进入下面的细胞。按几次“enter”不会解冻程序,唯一有效的是用鼠标选择另一个单元格
我有线程池的任务队列,每个任务都有卡住锁定其正在使用的所有资源的倾向。并且除非重新启动服务,否则这些无法释放。 ThreadPool 中有没有办法知道它的线程已经被卡住?我有一个使用超时的想法(虽然我
我制作了以下小程序来确定内存是否用于 freeze(X,Goal) 之类的目标回收时 X变得无法访问: %:- use_module(library(freeze)). % Ciao Prolog n
我有一个使用 swing 的简单 java 应用程序。然而,当我执行程序时,框架将会出现,但我无法单击任何地方,并且按钮仅在几秒钟后出现。我对 javas Swing 库非常陌生,所以我可能会丢失一些
我正在尝试创建一个简单的 TCP 客户端服务器应用程序接口(interface)用户可以在按下相应按钮时启动或停止服务器我创建了一个 StartServer 按钮,当用户按下按钮时它应该连接到服务
我正在尝试从 ftp 服务器下载文件,但在检索文件时卡住了。我正在使用 commons-net-3.6.jar 我注意到的事情 当我使用 ftpClient.enterRemotePassiveMod
我正在尝试编写一个函数,该函数将能够找到位于我系统上的可执行文件搜索路径中的任意可执行文件。我遇到了一些输入会导致 SearchPathW 的问题无限期地卡住,我不确定到底发生了什么。 std::op
我的 Nativescript 应用程序的许多页面中都有 RadSideDrawer。主应用程序组件有一个 page-router-outlet并且所有其他页面都通过导航加载到此组件中。带抽屉的页面包
我有一个最小的服务器,它等待客户端连接,然后他启动一个线程,将回复发送回客户端,问题是回复。 这是服务器的代码: int port = 1234; ServerSocket servSock =
我有一个使用 C# 的 WinForms 应用程序。我尝试从文件中读取一些数据并将其插入到数据表中。虽然此操作很忙,但我的表单卡住并且我无法移动它。有谁知道我该如何解决这个问题? 最佳答案 这可能是因
在我们学校最新的项目中,我遇到了一些问题。我想观察新条目的路径,该路径是由文件导向器按钮选择的,但如果我选择任何文件,整个窗口都会卡住...我猜它被卡住,因为调用了“observePath”方法,但我
当我输入一百万作为输入数字时,我的程序卡住了。我该如何解决这个问题? 我尝试将第二个 for 循环分离为第二个函数,但没有成功。 import java.io.*; public class Arra
早上好编译我的应用程序时,我在 Android Studio 上遇到问题。我在构建时没有收到关于 app:transformClassesWithDexBuilderForDebug 的任何输出错误,
我正在使用以下触发器 DELIMITER ; CREATE TRIGGER updateCount AFTER INSERT ON user_info FOR EACH ROW BEGIN UPDA
我是一名优秀的程序员,十分优秀!