import java.awt.image.*; import java.awt.*; import java.applet.*; public class Pildiskaleerimine3 extends Applet implements Runnable{ int laius=100; int korgus=100; BufferedImage pilt1=new BufferedImage(laius, korgus, BufferedImage.TYPE_INT_RGB); RescaleOp rop = new RescaleOp(0.97f, 0, null); Graphics2D g1=pilt1.createGraphics(); double x=100, y=100, kx=5*Math.random(), ky=7*Math.random(); boolean veel=true; int ooteaeg=10; void liiguta(){ if(x+kx>laius-5)kx=-Math.abs(kx); if(y+ky>korgus-5)ky=-Math.abs(ky); if(x+kx<5)kx=Math.abs(kx); if(y+ky<5)ky=Math.abs(ky); x+=kx; y+=ky; } void samm(){ liiguta(); rop.filter(pilt1,pilt1); g1.fillOval((int)x-5, (int)y-5, 10, 10); repaint(); } public void run(){ veel=true; while(veel){ samm(); try{Thread.sleep(ooteaeg);}catch(Exception e){} } } public Pildiskaleerimine3(){ g1.setColor(Color.green); new Thread(this).start(); } public void stop(){ veel=false; } public void paint(Graphics g){ g.drawImage(pilt1, 10, 10, this); } public void update(Graphics g){ paint(g); } public static void main(String argumendid[]){ Frame f=new Frame("Pildi muutmine"); f.add(new Pildiskaleerimine3()); f.setSize(130, 150); f.setVisible(true); } }