import java.awt.*; import java.awt.image.*; public class Tah05 extends Canvas{ int vx, vy, ux, uy, ax, ay, laius, korgus; int op=1; Image pilt, sahver; String lause=" "; Graphics piltg, sahverg; Tah05(int w, int h){ // resize(w, h); this.reshape(0, 0, w, h); laius=w; korgus=h; setBackground(Color.white); } public boolean mouseDown(Event e, int x, int y){ ux=x; uy=y; ax=x; ay=y; sahverg.drawImage(pilt, 0, 0, this); if(op==1){piltg.drawLine(ax, ay, ux, uy); repaint();} return super.mouseDown(e, x, y); } public boolean mouseDrag(Event e, int x, int y){ vx=ux; vy=uy; ux=x; uy=y; if(op==1){ piltg.drawLine(vx, vy, ux, uy);} if(op==2) {piltg.drawImage(sahver, 0, 0 , null); piltg.drawLine(ax, ay, ux, uy);} if(op==4){siseruutjuur();} repaint(); return super.mouseDrag(e, x, y); } public boolean keyDown(Event e, int key){ if(op==3){ if((char)e.key=='\177'){if(lause.length()>0) {lause=lause.substring(0, lause.length()-1);}} else{ lause=lause+String.valueOf((char)e.key);} piltg.drawImage(sahver, 0, 0, null); piltg.drawString(lause, ax, ay); repaint(); } return super.keyDown(e, key); } public void siseruutjuur(){ int dx, dy; dx=ux-ax; dy=uy-ay; piltg.drawImage(sahver, 0, 0, null); piltg.drawLine(ax, (int)(ay+dy*0.5),(int)(1+ax+0.05*dx), uy ); piltg.drawLine((int)(1+ax+0.05*dx), uy,(int)(3+ax+0.1*dx), ay ); piltg.drawLine((int)(3+ax+0.1*dx), ay ,(int)(ux-0.05*dx-1), ay ); piltg.drawLine((int)(ux-0.05*dx-1), ay, ux, (int)(ay+0.3*dy) ); } public void seaVarv(Color co){ piltg.setColor(co);} public void tagasi(){ piltg.drawImage(sahver, 0, 0, null); repaint();} public void tuhjaks(){ Color co; sahverg.drawImage(pilt, 0, 0, null); co=piltg.getColor(); piltg.setColor(Color.white); piltg.fillRect(0, 0, laius, korgus); piltg.setColor(co); repaint(); } public void joon(){ op=2;} public void sodi(){op=1;} public void kirjuta(){op=3; lause=" ";} public void ruutjuur(){op=4;} public void update(Graphics g){ // g.clipRect(Math.min(vx, ux)-1, Math.min(vy, uy)-1, Math.abs(vx-ux)+100, Math.abs(vy-uy)+100); // g.clipRect(0, 0, 50, 30); paint(g); } public void paint(Graphics g){ if (pilt==null){ pilt=createImage(size().width, size().height); piltg=pilt.getGraphics(); piltg.setColor(Color.black); sahver=createImage(size().width, size().height); sahverg=sahver.getGraphics(); } g.drawImage(pilt, 0, 0, null); } public String kokku(String s){ char tahed1[]; char tahed2[]=new char[laius*korgus]; char c; int i, koht1, koht2, arv; String abi; tahed1=s.toCharArray(); koht1=0; koht2=0; while(koht1s.length()-1)break; } abi=String.valueOf(arv); for (int ik=0; ik> 16) & 0xff; if (((pixels[j * laius + i] >> 16) & 0xff)==0){c[ik++]='m';} else if (((pixels[j * laius + i] >> 16) & 0xff)==255){c[ik++]='v';} else {c[ik++]='k';} } } s=new String(c); return kokku(s); } public void stringipilt(String s){ Image abi; int[] pixels = new int[laius*korgus]; char c[]=new char[laius*korgus]; int i, p; s=lahti(s); c=s.toCharArray(); p=s.length(); for(i=0; i