import java.awt.*; import java.applet.Applet; import java.util.*; import java.net.*; public class Cross extends Applet implements Runnable{ Thread th; Vector mvs; Updater udr; Bak bak; Checkbox stop; public void init(){ add(stop = new Checkbox("stop")); kon(); th = new Thread(this); th.start(); } public boolean action(Event e, Object o){ boolean res = super.action(e, o); if(e.target == stop){ if(th==null) return res; if(stop.getState()){ th.suspend(); }else{ th.resume(); } } return res; } public void kon(){ udr = new Updater(this); EzImg ezImg = new EzImg(this); mvs = new Vector(); bak = new Bak(this); udr.add(bak, 0); Dimension sz = new Dimension(16,16); Image img = ezImg.maru(sz,Color.blue); img = ezImg.alphaImg(img); MovImg mv = new MovImg(size(), img); udr.add(mv, 10); mvs.addElement(mv); img = ezImg.maru(new Dimension(32,32), Color.yellow); img = ezImg.alphaImg(img); mv = new MovImg(size(), img); udr.add(mv, 20); mvs.addElement(mv); img = ezImg.getImage("gif/hitsuji.gif"); if(img == null){ showStatus("Filed getImage"); }else{ mv = new MovImg(size(), img); udr.add(mv, 25); mvs.addElement(mv); } sz = new Dimension(32,32); img = ezImg.btn(sz,Color.red); img = ezImg.alphaImg(img); mv = new MovImg(size(), img); udr.add(mv, 30); mvs.addElement(mv); sz = new Dimension(64,64); img = ezImg.maru(sz,Color.magenta); img = ezImg.alphaImg(img, 128); mv = new MovImg(size(), img); udr.add(mv, 100); mvs.addElement(mv); } public void run(){ while(th.isAlive()){ try{ th.sleep(100); }catch(InterruptedException e){} work(); } } void work(){ Enumeration e = mvs.elements(); bak.cntup(udr); while(e.hasMoreElements()){ MovImg mv = (MovImg)e.nextElement(); mv.move(udr); } repaint(); } public void update(Graphics g){ udr.update(g); } } class Bak implements Drawer{ Dimension sz; Image img; int cnt, cntN; EzImg ezImg; public Bak(Applet ap){ sz = ap.size(); ezImg = new EzImg(ap); cntN = 50; cnt = cntN; img = null; } public void cntup(Updater udr){ if(++cnt>=cntN){ img = ezImg.maru(sz, Rnd.color()); udr.set(new Rectangle(sz)); cnt = 0; } } boolean done; public void draw(Graphics g, Rectangle r){ if(done) return; if(img==null) return; g.drawImage(img, 0, 0, null); done = true; } public void begin(){ done = false; } public void end(){} } // EOF