import java.awt.*; import java.applet.*; import java.lang.*; public class ball extends Applet implements Runnable{ Thread thre; Button Restart = new Button("Restart"); Button Continue = new Button("Continue"); Button Stop = new Button("Stop"); public void init(){ /* 初期設定 */ resize( size().width , size().height ); setBackground(Color.white); setLayout(new BorderLayout());//ボーダーレイアウトに Panel p = new Panel();//パネル作製 p.setLayout(new GridLayout(1,3,3,0)); p.add(Restart);//部品をパネルに貼り付け p.add(Continue); p.add(Stop); add("North", p);//パネルを右に貼り付け Continue.disable(); Stop.disable(); } /**イベント処理*/ public boolean handleEvent(Event e){ if (e.target instanceof Button){ if ("Continue".equals(e.arg)){ thre.resume(); Restart.disable(); Continue.disable(); Stop.enable(); } if ("Stop".equals(e.arg)){ thre.suspend(); Restart.enable(); Continue.enable(); Stop.disable(); } if ("Restart".equals(e.arg)){ thre = new Thread(this); thre.start(); Restart.disable(); Continue.disable(); Stop.enable(); } return true; } return true; } public void run() { /* 計算、アニメーションの中心部 */ while(thre!=null){ repaint(); try{ Thread.sleep(50);} catch (InterruptedException e) { } } } public void paint(Graphics g){ } public void update(Graphics g) { paint( g ); } public void start() { if(thre == null){ thre= new Thread(this); thre.start(); thre.suspend(); } } public void stop() { if(thre != null){ thre.stop(); thre=null; } } }