// sim.java -- みんな大好き被害予想シミュレーション -- // Dr.DOTIMPACT 1998/6/23 import java.applet.Applet; import java.awt.*; public class sim extends Applet implements Runnable { // 表示系 Thread ticker; Image buf; Graphics bufg; Button start, reset; Font button, disp; // 背景 MediaTracker mt; Image back; Rectangle rect; // 変数 boolean on, seq; int dia; public void init() { ticker = null; on = false; seq = false; dia = 0; // 背景読み込み back = getImage(getDocumentBase(), "map2__.gif"); mt = new MediaTracker(this); mt.addImage(back, 0); try { mt.waitForAll(); } catch(InterruptedException e) { return; } rect = new Rectangle(0, 0, back.getWidth(this), back.getHeight(this)); // バッファ buf = createImage(rect.width, rect.height); bufg = buf.getGraphics(); // フォント button = new Font("Dialog", Font.PLAIN, 12); disp = new Font("Helvetica", Font.PLAIN, 18); // ボタン setLayout(null); start = new Button("Start"); reset = new Button("Reset"); start.reshape(405, 5, 40, 20); reset.reshape(405, 30, 40, 20); add(start); add(reset); } public void start() { if (ticker == null) { ticker = new Thread(this); ticker.start(); } } public void stop() { if (ticker != null) { ticker.stop(); ticker = null; } } public void run() { draw_buffer(); while(true) { try { Thread.sleep(50); } catch(Exception e) {} if(seq) { dia++; if(dia >= 200) dia = 200; draw_buffer(); repaint(); } } } public boolean action(Event ev, Object what) { if(ev.target == start) { on = true; seq = true; } if(ev.target == reset) { on = false; seq = false; dia = 0; draw_buffer(); repaint(); } return true; } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { g.drawImage(buf, 0, 0, this); } public void draw_buffer() { int i; // 背景の地図 bufg.drawImage(back, 0, 0, this); // 被害範囲(何の?) if(on) { bufg.setColor(Color.red); bufg.fillOval(280 - dia/2, 100 - dia/2, dia, dia); bufg.fillOval(380 - dia/4, 150 - dia/4, dia/2, dia/2); bufg.fillOval(200 - dia/2, 220 - dia/2, dia, dia); } // 縮尺線らしきもの(雰囲気) bufg.setColor(Color.white); for(i = 0 ; i <= rect.width ; i = i + 100) { bufg.drawLine(i, 0, i, rect.height); } for(i = 0 ; i <= rect.height ; i = i + 100) { bufg.drawLine(0, i, rect.width, i); } // カウンタらしきもの(雰囲気) bufg.setFont(disp); bufg.drawString("scale : " + dia, 5, 20); } }