js til Java Applet
Hej,Jeg har noget JavaScript kode, som jeg gerne vil have oversat til Java, så det vises i en applet. Er der nogle af Jer som kan finde ud at det? Koden er her:
function gif(name,w,h,code){
this.name=name;
this.w=w;
this.h=h;
this.code=code;
this.top=top;
this.left=left;
}
function top(scale){ // method of gif
if (this.code==1 || this.code==3) return(190-0.5*Math.round(scale*this.h));
if (this.code==0 || this.code==4 || this.code==7) return(190-Math.round(scale*this.h));
return(190);
}
function left(scale){ // method of gif
if (this.code==0 || this.code==2) return(190-0.5*Math.round(scale*this.w));
if (this.code==3 || this.code==6 || this.code==7) return(190-Math.round(scale*this.w));
return(190);
}
function sect(no,nosectors){
this.freqWedge=new wedge(0,"f",no,nosectors,1,0,102,204);
this.speedWedge=new wedge(1,"v",no,nosectors,2/3,0,0,0);
this.energyWedge=new wedge(2,"e",no,nosectors,1/3,255,0,0);
}
function wedge(type,name,no,nosectors,width,r,g,b){
this.type=type;
this.name=name;
this.no=no;
this.width=width; // width of wedge
this.r=r; // red
this.g=g; // green
this.b=b; // blue
this.gif=gifs[type][nosectors/4-2][no];
this.change=change; //method
this.max=max; // method
this.draw=draw; // method
if (this.name=="f"){
this.value=parseFloat(iiFm[this.name+this.no].value);
}else{
if (this.name=="v"){
this.value=parseFloat(iiFm["v"+this.no].value)*parseFloat(iiFm["f"+this.no].value);
}else{
var v=parseFloat(iiFm["v"+this.no].value);
var f=parseFloat(iiFm["f"+this.no].value);
this.value=v*v*v*f;
}
}
}
function max(){ //method of wedge
var x=0;
maximum=-999999999;
for (var i=0;i<nosectors;i++){
if (this.name=="v"){
x=sector[i].speedWedge.value;
}else{
if (this.name=="f"){
x=sector[i].freqWedge.value;
}else{
x=sector[i].energyWedge.value;
}
}
if (x>maximum) maximum=x;
}
return(maximum);
}
function change(){ //method of wedge
this.value=parseFloat(iiFm[this.name+this.no].value);
var f=parseFloat(iiFm["f"+this.no].value);
var v=parseFloat(iiFm["v"+this.no].value);
sector[this.no].speedWedge.value=v*f;
sector[this.no].energyWedge.value=v*v*v*f;
}
function draw(){ //method of wedge
var r=1;
var m=this.max();
if (m>0) r=this.value/m;
if (r==0) return; // Netscape displays images with size=0 at full size
var w=Math.round(this.gif.w*r);
var h=Math.round(this.gif.h*r);
var id=this.name+this.no;
if (NS4) win.document.write("<LAYER>");
win.document.write("<DIV STYLE='position: absolute; left: "+this.gif.left(r)+"; top: "+this.gif.top(r)+";'>");
win.document.write("<IMG SRC='"+this.gif.name+".gif' WIDTH='"+w+"' HEIGHT='"+h+"'></DIV>");
if (NS4) win.document.write("</LAYER>");
}
var NS4 = (document.layers) ? 1 : 0;
var IE4 = (document.all||ijDOM) ? 1 : 0;
iiFm=document.forms.calcform.elements;
iiVr=new Array("Plot,"Plot","Plot","Plot","Plot","Plot");
iiPr=new Array("Program","Program","Program","Program","Program","Program");
reset=false;
win=null;
// code use 0=top half, 1=right half, 2 bottom half, 3 left half
// 4=top right quadrant, 5=bottom right quadrant, 6=bottom left quadrant, 7=top left quadrant
f8=new Array(new gif("f80",142,185,0),new gif("f81",171,171,4),new gif("f82",185,142,1),new gif("f83",171,171,5),new gif("f84",142,185,2),new gif("f85",171,171,6),new gif("f86",185,142,3),new gif("f87",171,171,7));
f12=new Array(new gif("f120",98,185,0),new gif("f121",133,181,4),new gif("f122",181,133,4),new gif("f123",185,98,1),new gif("f124",181,133,5),new gif("f125",133,181,5),new gif("f126",98,185,2),new gif("f127",133,181,6),new gif("f128",181,133,6),new gif("f129",185,98,3),new gif("f1210",181,133,7),new gif("f1211",133,181,7));
f16=new Array(new gif("f160",72,185,0),new gif("f161",104,181,4),new gif("f162",154,154,4),new gif("f163",181,104,4),new gif("f164",185,72,1),new gif("f165",181,104,5),new gif("f166",154,154,5),new gif("f167",104,181,5),new gif("f168",72,185,2),new gif("f169",104,181,6),new gif("f1610",154,154,6),new gif("f1611",181,104,6),new gif("f1612",185,72,3),new gif("f1613",181,104,7),new gif("f1614",154,154,7),new gif("f1615",104,181,7));
fgifs=new Array(f8,f12,f16);
v8=new Array(new gif("v80",98,185,0),new gif("v81",163,163,4),new gif("v82",185,98,1),new gif("v83",163,163,5),new gif("v84",98,185,2),new gif("v85",163,163,6),new gif("v86",185,98,3),new gif("v87",163,163,7));
v12=new Array(new gif("v120",66,185,0),new gif("v121",120,175,4),new gif("v122",175,120,4),new gif("v123",185,66,1),new gif("v124",175,120,5),new gif("v125",120,175,5),new gif("v126",66,185,2),new gif("v127",120,175,6),new gif("v128",175,120,6),new gif("v129",185,66,3),new gif("v1210",175,120,7),new gif("v1211",120,175,7));
v16=new Array(new gif("v160",50,185,0),new gif("v161",94,181,4),new gif("v162",149,149,4),new gif("v163",181,94,4),new gif("v164",185,50,1),new gif("v165",181,94,5),new gif("v166",149,149,5),new gif("v167",94,181,5),new gif("v168",50,185,2),new gif("v169",94,181,6),new gif("v1610",149,149,6),new gif("v1611",181,94,6),new gif("v1612",185,50,3),new gif("v1613",181,94,7),new gif("v1614",149,149,7),new gif("v1615",94,181,7));
vgifs=new Array(v8,v12,v16);
e8=new Array(new gif("e80",50,185,0),new gif("e81",149,149,4),new gif("e82",185,50,1),new gif("e83",149,149,5),new gif("e84",50,185,2),new gif("e85",149,149,6),new gif("e86",185,50,3),new gif("e87",149,149,7));
e12=new Array(new gif("e120",34,185,0),new gif("e121",108,170,4),new gif("e122",170,108,4),new gif("e123",185,34,1),new gif("e124",170,108,5),new gif("e125",108,170,5),new gif("e126",34,185,2),new gif("e127",108,170,6),new gif("e128",170,108,6),new gif("e129",185,34,3),new gif("e1210",170,108,7),new gif("e1211",108,170,7));
e16=new Array(new gif("e160",26,185,0),new gif("e161",84,177,4),new gif("e162",141,141,4),new gif("e163",177,84,4),new gif("e164",185,26,1),new gif("e165",177,84,5),new gif("e166",141,141,5),new gif("e167",84,177,5),new gif("e168",26,185,2),new gif("e169",84,177,6),new gif("e1610",141,141,6),new gif("e1611",177,84,6),new gif("e1612",185,26,3),new gif("e1613",177,84,7),new gif("e1614",141,141,7),new gif("e1615",84,177,7));
egifs=new Array(e8,e12,e16);
gifs= new Array(fgifs,vgifs,egifs);
init();
function init(){
reset=false;
nosectors=parseInt(iiFm.nosectors.options[iiFm.nosectors.selectedIndex].value);
sector=new Array(0);
for (var i=0;i<16;i++){ sector[i]=new sect(i,nosectors); }
}
function set(){ // used by reset button
reset=true;
}
function display(){
if (reset) init();
win=open("","skxy_99","resizable=no,width=400,height=400");
win.document.write("<HEAD><TITLE>"+iiVr[ijLangNo]+"</TITLE></HEAD><BODY BGCOLOR='#FFFFFF'>");
for (var i=0;i<nosectors;i++){
if (document.forms[1].freq.checked==true) sector[i].freqWedge.draw();
if (document.forms[1].speed.checked==true) sector[i].speedWedge.draw();
if (document.forms[1].energy.checked==true) sector[i].energyWedge.draw();
}
if (NS4) win.document.write("<LAYER>");
win.document.write("<DIV STYLE='position: absolute; left: 5; top: 5;'><IMG SRC='circles.gif' WIDTH='371' HEIGHT='371' ALIGN='BOTTOM' BORDER='0' NATURALSIZEFLAG='3'></DIV>");
if (NS4) win.document.write("</LAYER><LAYER>");
win.document.write("<DIV STYLE='position: absolute; left: 5; top: 380;'>");
//win.document.write("<FONT SIZE='1' FACE='gillsans, frutiger, arial, helvetica, geneva' COLOR='#0066CC'>"+iiPr[ijLangNo]+" copyright © 1999-2003 Søren Krohn</FONT></DIV>");
if (NS4) win.document.write("</LAYER>");
win.document.close();
win.focus();
win=null;
}
