当前位置: 代码迷 >> Eclipse >> Applet应用程序为何不能在Eclipse里面运行
  详细解决方案

Applet应用程序为何不能在Eclipse里面运行

热度:71   发布时间:2016-04-23 01:24:31.0
Applet应用程序为什么不能在Eclipse里面运行
1.在web上面运行是这样的.

2.在Eclipse里面运行是这样的.

3.下面是代码
4.问题:是不是要自己创建显示图形extend JFrame什么的?程序报空指针异常,未初始化实在弄不明白。如何在Eclipse里面显示出来?
package example;
class Node {
    double x,y,dx,dy;
    boolean fixed;
    String lbl;
}
class Edge {
    int from,to;
    double len;
}
class GraphPanel extends Panel
    implements Runnable, MouseListener, MouseMotionListener {
    Graph graph;
    int nnodes;
    Node nodes[] = new Node[100];
    int nedges;
    Edge edges[] = new Edge[200];
    Thread relaxer,stress;
    boolean random;
    int numMouseButtonsDown = 0;
    GraphPanel(Graph graph) {
this.graph = graph;
addMouseListener(this);
    }
    int findNode(String lbl) {
for (int i = 0 ; i < nnodes ; i++) {
    if (nodes[i].lbl.equals(lbl)) {return i;}
}
return addNode(lbl);
    }
    int addNode(String lbl) {
Node n = new Node();
n.x = 10 + 380*Math.random();
n.y = 10 + 380*Math.random();
n.lbl = lbl;
nodes[nnodes] = n;
return nnodes++;
    }
    void addEdge(String from, String to, int len) {
Edge e = new Edge();
e.from = findNode(from);
e.to = findNode(to);
e.len = len;
edges[nedges++] = e;
    }
    public void run() {
        Thread me = Thread.currentThread();
while (relaxer == me) {
    relax();
    if (random && (Math.random() < 0.03)) {
Node n = nodes[(int)(Math.random() * nnodes)];
if (!n.fixed) {
    n.x += 100*Math.random() - 50;
    n.y += 100*Math.random() - 50;
}
graph.play(graph.getCodeBase(), "audio/drip.au");
    }
    try {
Thread.sleep(100);
    } catch (InterruptedException e) {
break;
    }
}
    }
    synchronized void relax() {
for (int i = 0 ; i < nedges ; i++) {
    Edge e = edges[i];
    double vx = nodes[e.to].x - nodes[e.from].x;
    double vy = nodes[e.to].y - nodes[e.from].y;
    double len = Math.sqrt(vx * vx + vy * vy);
  相关解决方案