我正在尝试为我的网络课程运行these applets。当我试图在浏览器中从链接运行它们时,它们什么都不做。所以我决定尝试在IntelliJ中编译它们,但是当我运行代码时它并没有做任何事情。没有错误消息返回。我做的唯一改变源代码的代码是添加主要方法并删除包声明。下面是我试图运行小程序:如何在Intellij IDEA中运行Applet?

Java代码

///

//LineSimApllet

//written by David Grangier, Institut Eurecom, France

//[email protected]

///

//imports

import java.awt.*;

import java.awt.event.*;

import java.awt.image.*;

import java.applet.*;

import java.util.*;

//Applet Class

public class LineSimApplet extends Applet {

//buttons

Button start = new Button("Start");

Button stop = new Button("Reset");

//features lists

MyChoice length = new MyChoice(new String[]{"10 km", "100 km", "1000 km"}, new double[]{10E3, 100E3, 1E6}, 3);

MyChoice rate = new MyChoice(new String[]{"512 kps", "1 Mbps", "10 Mbps", "100 Mbps"}, new double[]{512E3, 1E6, 10E6, 100E6}, 2);

MyChoice size = new MyChoice(new String[]{"100 Bytes", "500 Bytes", "1 kBytes"}, new double[]{8E2, 4E3, 8E3}, 1);

//to simulate time

Thread timerThread;

TickTask timerTask;

boolean simulationRunning = false;

//communication line

Line myLine;

public void init() {

try {

setBackground(Color.white);

add(new Label("Length", Label.RIGHT));

add(length);

add(new Label("Rate", Label.RIGHT));

add(rate);

add(new Label("Packet size", Label.RIGHT));

add(size);

//start

start.addActionListener(

new ActionListener() {

public void actionPerformed(ActionEvent event) {

launchSim();

}

});

add(start);

//stop

Button stop = new Button("Reset");

stop.addActionListener(

new ActionListener() {

public void actionPerformed(ActionEvent event) {

stopSim();

//clear line

myLine.sendTime(0);

//redraw cleared line

LineSimApplet.this.repaint();

}

});

add(stop);

//line

myLine = new Line(40, 50, 450, 10);

} catch (Exception e) {

e.printStackTrace();

}

}

public void paint(Graphics g) {

update(g); // eliminate flashing : update is overriden

}

public void update(Graphics g) { //work on a offscreen image

Dimension offDimension = getSize();

Image offImage = createImage(offDimension.width, offDimension.height);

Graphics offGraphics = offImage.getGraphics();

myLine.drawLine(offGraphics);

//sender

offGraphics.setColor(Color.blue);

offGraphics.fillRect(10, 40, 30, 30);

offGraphics.setColor(Color.black);

offGraphics.drawString("Sender", 5, 90);

offGraphics.drawRect(10, 40, 30, 30);

//receiver

offGraphics.setColor(Color.blue);

offGraphics.fillRect(490, 40, 30, 30);

offGraphics.setColor(Color.black);

offGraphics.drawString("Receiver", 485, 90);

offGraphics.drawRect(490, 40, 30, 30);

offGraphics.drawString("Propagation speed : 2.8 x 10^8 m/sec", 175, 105);

//display offscreen image

g.drawImage(offImage, 0, 0, this);

}

private void launchSim() {

setupEnabled(false);

//setup line

myLine.setup(length.getVal(), rate.getVal());

myLine.emitPacket(size.getVal(), 0);

//setup timer

timerTask = new TickTask(1E-5, myLine.totalTime());

timerThread = new Thread(timerTask);

//start simulation

simulationRunning = true;

timerThread.start();

}

private void stopSim() {

timerTask.endNow();

simulationRunning = false;

setupEnabled(true);

}

public void setupEnabled(boolean value) {

start.setEnabled(value);

length.setEnabled(value);

rate.setEnabled(value);

size.setEnabled(value);

}

//my choice

class MyChoice extends Choice {

private double vals[];

public MyChoice(String items[], double values[], int defaultValue) {

for (int i = 0; i < items.length; i++) {

super.addItem(items[i]);

}

vals = values;

select(defaultValue - 1);

}

public double getVal() {

return vals[super.getSelectedIndex()];

}

}

//tickTask

class TickTask implements Runnable {

private double counter;

private double length;

private double tick;

public TickTask(double t, double l) {

length = l;

tick = t;

counter = 0;

}

public void run() {

while (LineSimApplet.this.simulationRunning) {

counter += tick;

LineSimApplet.this.myLine.sendTime(counter);

LineSimApplet.this.repaint();

if (counter >= length) {

LineSimApplet.this.myLine.clearPackets();

LineSimApplet.this.timerThread.suspend();

}

try {

LineSimApplet.this.timerThread.sleep(50);

} catch (Exception e) {

}

}

}

public void endNow() {

length = counter;

}

}

}

//Line class

class Line {

//graphic variables

private int gX;

private int gY;

private int gWidth;

private int gHeight;

//characteristic variables

final double celerity = 2.8E+8;

private double length;

private double rate;

//simulation variables

private double time;

private Packet myPacket;

public Line(int x, int y, int w, int h) {

//graphic init

gX = x;

gY = y;

gWidth = w;

gHeight = h;

}

public void setup(double l, double r) {

length = l;

rate = r;

}

void sendTime(double now) {

time = now; //update time

removeReceivedPackets(now);

}

void emitPacket(double s, double eT) {

myPacket = new Packet(s, eT);

}

private void removeReceivedPackets(double now) {

if (!(myPacket == null)) {

if (now > myPacket.emissionTime + (myPacket.size/rate) + length * celerity) {

clearPackets();

}

}

}

public void clearPackets() {

myPacket = null;

}

public double totalTime() {

double emmissionTime = (myPacket.size/rate);

double onLineTime = (length/celerity);

return (emmissionTime + onLineTime);

}

public void drawLine(Graphics g) {

g.setColor(Color.white);

g.fillRect(gX, gY + 1, gWidth, gHeight - 2);

g.setColor(Color.black);

g.drawRect(gX, gY, gWidth, gHeight);

g.setColor(Color.red);

g.drawString(timeToString(time), gX + gWidth/2 - 10, gY + gHeight + 15);

drawPackets(g);

}

private void drawPackets(Graphics g) {

if (!(myPacket == null)) {

double xfirst;

double xlast;

//compute time units

xfirst = time - myPacket.emissionTime;

xlast = xfirst - (myPacket.size/rate);

//compute position

xfirst = xfirst * celerity * gWidth/length;

xlast = xlast * celerity * gWidth/length;

if (xlast < 0) {

xlast = 0;

}

if (xfirst > gWidth) {

xfirst = gWidth;

}

//draw

g.setColor(Color.red);

g.fillRect(gX + (int) (xlast), gY + 1, (int) (xfirst - xlast), gHeight - 2);

}

}

static private String timeToString(double now) {

String res = Double.toString(now * 1000);

int dot = res.indexOf('.');

String deci = res.substring(dot + 1) + "000";

deci = deci.substring(0, 3);

String inte = res.substring(0, dot);

return inte + "." + deci + " ms";

}

public static void main(String[] args) {

LineSimApplet ls = new LineSimApplet();

ls.init();

}

}

class Packet {

double size;

double emissionTime;

Packet(double s, double eT) {

size = s;

emissionTime = eT;

}

}

如何运行使用的IntelliJ这个小程序?

html运行applet idea,如何在Intellij IDEA中运行Applet?相关推荐

  1. idea上如何跑java程序_java – 如何在Intellij IDEA中运行Applet?

    我正在尝试为我的网络课程运行 these applets.当我尝试在浏览器中从链接运行这些时,他们什么也没做.所以我决定尝试在IntelliJ中编译它们,但是当我运行代码时它没有做任何事情.没有返回错 ...

  2. html 里运行php文件,如何在HTML文件中运行PHP脚本

    欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 当访问一个网页时,服务器会根据文件扩展名来判断如何处理页面,一般来说,当检查到扩展名为htm或html时,服务器将文件直接 ...

  3. 如何在 IntelliJ IDEA 中整合 Maven、Tomcat 部署 Web 应用

    如何在 IntelliJ IDEA 中整合 Maven.Tomcat 部署 Web 应用 笔者的环境: JDK 11.0.12 Maven 3.6.3 Tomcat 9.0.41(Servlet 4. ...

  4. 如何在 IntelliJ IDEA 中快速生成 JavaDoc 注释模板

    如何在 IntelliJ IDEA 中快速生成 JavaDoc 注释模板 此博客存在上一个版本,如果读者对笔者以前版本的博客依然感兴趣,可以访问此链接:https://blog.csdn.net/wa ...

  5. 如何在Intellij IDEA中集成Gitlab

    如何在Intellij IDEA中集成Gitlab 2018年06月11日 16:05:14 葬月魔帝 阅读数:9747 据说在微软收购github当天,一大批用户纷纷转向了gitlab和bitbuc ...

  6. 在Intellij IDEA中运行Vaadin应用

    在本文中,我将向您展示如何使用Intellij IDEA运行vaadin应用程序. Vaadin提供了一些用于Eclipse和Netbeans的插件. 但是对于Intellij IDEA来说,还没有插 ...

  7. 如何在Docker容器中运行GUI程序

    如何在Docker容器中运行GUI程序 各位,今天我们将学习如何在Docker之中运行GUI程序.我们可以轻易地在Docker容器中运行大多数GUI程序且不出错.Docker是一个开源项目,提供了一个 ...

  8. idea 注解制表符_如何在IntelliJ IDEA中使用制表符进行缩进?

    如何在IntelliJ IDEA中使用制表符进行缩进? 如何在IntelliJ IDEA 11.0中使用制表符而不是多个空格进行缩进? 我有"使用制表符" 检查"代码风格 ...

  9. 安卓linux shell,如何在Android SHELL中运行C应用程序

    我想运行在C上编写的hello世界,并使用 Android toolchain 9进行编译,但是我遇到了问题:默认情况下,我没有权限启动它,我无法使用chmod来更改权限. 我使用Android 2. ...

最新文章

  1. 马尔科夫随机场的基本概念
  2. 每天一个 Linux 命令(13):less 命令
  3. java知识点7——面向过程和面向对象、面向对象的内存分析、构造方法
  4. Dubbo(二)之SpringBoot nacos集成
  5. 又被分治题卡住好几个小时!用最笨的方法搞懂分治法边界,告别死循环!
  6. Oracle 10G2 for CentOS 5.2 安装截图详解
  7. 3dmax2021渲染器下载安装教程VRay4.3渲染器下载安装教程
  8. 北斗导航 | dBW/dBm/W快速换算方法
  9. 世界各国Google域名后缀对照表
  10. 方框加对勾怎么输入_如何打出带方框的对号
  11. msi z170 网卡 linux,麻雀虽小五脏俱全:msi 微星 发布 Z170I Gaming Pro AC Mini-ITX主板...
  12. 怎样用计算机才能更快,如何让Win7电脑运行更快更流畅?
  13. 工业机器人视觉实训平台
  14. C# CSharp计算标准偏差 重复精度 和Excel中的STDEV函数相同
  15. 光线:提高照片的艺术感
  16. Android 仿美拍,秒拍 ,视频封面选择.有图有真相.
  17. leetcode(力扣) 347. 前 K 个高频元素(优先队列 堆 哈希计数器)
  18. 华为鸿蒙os尝鲜,华为鸿蒙os尝鲜版
  19. Jess学习基础(二)
  20. CCF计算机软件能力认证 C++ JSON查询

热门文章

  1. 使用Hexo的helper-live2d插件自定义博客看板娘
  2. 华为云服务器安全组开启宝塔面板8888端口配置教程
  3. Linux load average详解
  4. 选择美国独立服务器时需要注意什么?
  5. 功能强大的升级软件FREIA_jimyu,四步刷机法(更新EEP)
  6. Git:Git初始化(git config)
  7. 灵魂画手必读:只需完成手画线稿,让AI算法帮你自动上色
  8. 全球及中国芴行业投资前景与投资策略分析报告2022-2028年
  9. vs19c++求arccos值
  10. 【大学生期末大作业】HTML+CSS+JavaScript — 模仿博客网站设计(Web)