📄 route.java
字号:
/*********************************************************************
% File : Route.java
% Author : Neng-Fa ZHOU
% Date : 1998
% Purpose: Java part of a multi-layer channel router
*********************************************************************/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.applet.*;
import bprolog.plc.Plc;
public
class Route extends Applet {
int maxComps = 100;
public int screenWidth=600;
public int screenHeight=400;
public Hashtable ht;
DJComponent[] comps = new DJComponent[maxComps];
DJComponent comp;
int noComps = 0;
Color color = Color.black;
public static void main(String args[]) {
Frame f = new Frame("Route");
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}});
Route dj = new Route();
dj.init();
f.add("Center",dj);
f.setSize(dj.screenWidth,dj.screenHeight);
f.show();
dj.run();
System.exit(0);
}
public void init(){
initializeHashtable();
}
public void run() {
Plc.startPlc(new String []{});
Plc goal = new Plc("go", new Object[] {this});
Plc.exec("load('route')");
goal.call();
while (true);
}
void initializeHashtable(){
ht = new Hashtable(13);
ht.put("black",Color.black);
ht.put("blue",Color.blue);
ht.put("cyan",Color.cyan);
ht.put("darkGray",Color.darkGray);
ht.put("gray",Color.gray);
ht.put("green",Color.green);
ht.put("lightGray",Color.lightGray);
ht.put("magenta",Color.magenta);
ht.put("orange",Color.orange);
ht.put("pink",Color.pink);
ht.put("red",Color.red);
ht.put("white",Color.white);
ht.put("yellow",Color.yellow);
}
public void paint(Graphics g){
for (int i=0;i<noComps;i++) comps[i].draw();
}
void expandCompsIfNecessary(){
DJComponent[] anotherComps;
if (noComps==comps.length){
anotherComps = new DJComponent[comps.length*2];
for (int i=0;i<comps.length;i++) // copy
anotherComps[i] = comps[i];
comps = anotherComps;
}
}
public void setColor(String cstring){
color = (Color)ht.get(cstring);
}
public void addLine(Integer x1, Integer y1, Integer x2, Integer y2){
expandCompsIfNecessary();
comp = new DJLine(this,x1.intValue(),y1.intValue(),x2.intValue(),y2.intValue(),color);
comp.draw();
comps[noComps++] = comp;
}
public void addOval(Integer x, Integer y, Integer w, Integer h, Integer fill){
expandCompsIfNecessary();
comp = new DJOval(this,x.intValue(),y.intValue(),w.intValue(),h.intValue(),color,fill.intValue());
comp.draw();
comps[noComps++] = comp;
}
public void sleep(Integer mill) {
try {
Thread.sleep(mill.intValue(),0);
} catch(InterruptedException e) {}
}
}
abstract class DJComponent {
int x, y, width, height;
Applet ap;
Color color = Color.black;
Font font;
abstract void draw();
public DJComponent(Applet ap, int x, int y, int width, int height,Color color){
this.ap = ap;
this.x = x;
this.y = y;
this.width = width;
this.height= height;
this.color = color;
}
}
class DJLine extends DJComponent {
int x1,y1,x2,y2;
public DJLine(Applet ap, int x1, int y1, int x2, int y2,Color color){
super(ap,0,0,0,0,color);
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}
void draw(){
Graphics g = ap.getGraphics();
g.setColor(color);
g.drawLine(x1,y1,x2,y2);
}
}
class DJOval extends DJComponent {
boolean fill;
public DJOval(Applet ap, int x, int y, int width, int height,Color color,int fill){
super(ap,x,y,width,height,color);
if (fill==0) this.fill = false; else this.fill = true;
}
void draw(){
Graphics g = ap.getGraphics();
g.setColor(color);
if (fill)
g.fillOval(x,y,width,height);
else
g.drawOval(x,y,width,height);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -