// // // VECG Copyright 1998-2003, Foundation Internet Services // // import java.net.*; import java.io.*; import java.applet.*; import java.awt.*; public class Vecg extends Applet { URL url; int leadOn = 12; TextArea text = new TextArea(); Choice ls = new Choice(); Choice dx = new Choice(); DataInputStream inStream; Ecg[] lead = new Ecg[12]; Ecg[] plane = new Ecg[2]; int[][] tears = new int[120][3]; int numtears; String descText; String startVecg; boolean highlight; public void init() { lead[0] = new Ecg("I", 0,0); lead[1] = new Ecg("II",0,1); lead[2] = new Ecg("III",0,2); lead[3] = new Ecg("aVR",1,0); lead[4] = new Ecg("aVL",1,1); lead[5] = new Ecg("aVF",1,2); lead[6] = new Ecg("V1",2,0); lead[7] = new Ecg("V2",2,1); lead[8] = new Ecg("V3",2,2); lead[9] = new Ecg("V4",3,0); lead[10] = new Ecg("V5",3,1); lead[11] = new Ecg("V6",3,2); plane[0] = new Ecg("Frontal",0); plane[1] = new Ecg("Transverse",2); setLayout(null); add(dx); add(ls); add(text); loadChoice(dx,"vecgs"); loadChoice(ls,"leadsys"); text.reshape(5,5,340,100); dx.reshape(350,5,150,15); ls.reshape(350,30,150,15); startVecg = getParameter("startwith"); if ( startVecg == null ) { startVecg = "normal"; } dx.select(startVecg); loadVe(); loadLd(); } void loadChoice(Choice which, String file){ String inline; try{ url= new URL(getDocumentBase(),file); inStream = new DataInputStream(url.openStream()); while((inline = inStream.readLine()) != null) { which.addItem(inline.trim()); } } catch (MalformedURLException ex) { text.setText("Bad URL"); } catch (IOException ex) { text.setText("IO Exception"); } } void loadVe(){ String inline; descText = ""; try{ url= new URL(getDocumentBase(), dx.getSelectedItem() + ".ve"); inStream = new DataInputStream(url.openStream()); inline = inStream.readLine(); numtears = Integer.parseInt(inline.trim()); for (int i=0; i < numtears; i++){ for (int j=0; j<3; j++){ inline = inStream.readLine(); tears[i][j] = Integer.parseInt(inline.trim()); } } while((inline = inStream.readLine()) != null) { descText += inline + "\n"; } } catch (MalformedURLException ex) { text.setText("Bad URL"); } catch (IOException ex) { text.setText("IO Exception"); } } void loadLd(){ String inline; try{ url = new URL(getDocumentBase(), ls.getSelectedItem() + ".ld"); inStream = new DataInputStream(url.openStream()); for (int i=0; i < 12; i++){ inline = inStream.readLine(); lead[i].vx = -Integer.parseInt(inline.trim()); inline = inStream.readLine(); lead[i].vy = -Integer.parseInt(inline.trim()); inline = inStream.readLine(); lead[i].vz = -Integer.parseInt(inline.trim()); lead[i].vl = Math.sqrt(lead[i].vx*lead[i].vx + lead[i].vy*lead[i].vy + lead[i].vz*lead[i].vz); } } catch (MalformedURLException ex) { text.setText("Bad URL"); } catch (IOException ex) { text.setText("IO Exception"); } } public void update(Graphics g){ paint(g); } public void paint(Graphics g){ int voltage; Rectangle r = bounds(); g.setColor(Color.white); g.fillRect(r.x,r.y,r.width,r.height); for (int i = 0; i < 2; i++){ plane[i].drawAxes(g); } for (int i = 0; i < 12; i++){ highlight = false; if (i==leadOn) highlight = true; lead[i].drawBox(g,highlight); } for (int i=0; i