 // 再帰呼出しで円を描画 [Circle.java](JDK 1.0.2)
 import java.applet.*;
 import java.awt.*;
 //!import java.awt.event.*;  // JDK 1.1
 //!public class Circle extends Applet
 //!       implements ActionListener,ItemListener { // JDK 1.1
 public class Circle extends Applet { //!
    int a=1;      // 円の数の初期値
    int n=1;      // 繰り返し回数の初期値
    Choice aChoice,nChoice;  // チョイス
    Button button_rw;        // Re-writeボタン
    public void init() {     // ロード時の初期化メソッド
       aChoice = new Choice();     // チョイス
       nChoice = new Choice();     // チョイス
       for (int i=1; i<=7; i++) {  // チョイスの設定
          aChoice.addItem(""+i);
          nChoice.addItem(""+i);
       }
       button_rw=new Button("Re-write");  // ボタン
       add(button_rw);                    // Re-writeボタン
       add(aChoice);                      // チョイス
       add(new Label("Number"));          // ラベル
       add(nChoice);                      // チョイス
       add(new Label("Loop"));            // ラベル
  //!     button_rw.addActionListener(this); // JDK 1.1
  //!     aChoice.addItemListener(this);     // JDK 1.1
  //!     nChoice.addItemListener(this);     // JDK 1.1
    } //end init
  //!  //========= JDK 1.1 イベント処理(ボタン) ===============
  //!  public void actionPerformed(ActionEvent e) { // JDK 1.1
  //!     if (e.getSource() == button_rw) {   // Re-writeボタン
  //!        repaint();
  //!     } //end if
  //!  } //end actionPerformed
  //!  //========= JDK 1.1 イベント処理(チョイス) =============
  //!  public void itemStateChanged(ItemEvent e) {// JDK 1.1
  //!     if (e.getSource() == aChoice) {
  //!        a=aChoice.getSelectedIndex()+1;    // aの取出し
  //!     } else if (e.getSource() == nChoice) {
  //!        n=nChoice.getSelectedIndex()+1;    // nの取出し
  //!     } //end if
  //!  } //end itemStateChanged
  //============= JDK 1.0.2 イベント処理 ======================
  public boolean action(Event e, Object o) {  //! イベントの処理
     String label = o.toString();             //!
     if (e.target instanceof Button) {        //! Re-writeボタン
        if (label.equals("Re-write")) { repaint(); } //!
     } else if (e.target instanceof Choice) { //! チョイスの変更 
        a=aChoice.getSelectedIndex()+1;       //! aの取出し
        n=nChoice.getSelectedIndex()+1;       //! nの取出し
     }            //!
     return true; //! 
  } //end action  //!
    //================ グラフィックスの表示 ================
    public void paint( Graphics g ) {
       double x,y,r;
    //!   int w=getSize().width;  // 横の大きさ JDK 1.1
       int w=size().width;        //!横の大きさ
       x=w/2.0; y=x+50; r=x-20;   //(a) 中心(x,y),半径:r
       rcircle(g,n,x,y,r);        //(b) 再帰呼出し
    } //end paint
    //=========== 中心：(x,y), 半径：r, 回数：n ============
    public void rcircle
       (Graphics g, int nn, double x, double y, double r) {
       if (nn <= 0) { return; }
       double sr,d,t,xx,yy,rr;
       g.drawOval((int)(x-r),(int)(y-r),
                  (int)(r+r),(int)(r+r));       //(c)円を描く
       d=(180.0-360.0/a)/2.0;                   //(d)角度の計算
       rr=r/(1.0/Math.cos(Math.PI*d/180.0)+1.0);//(e)内円の半径
       t=Math.PI*2.0/a;              //(f) 角度=π×(360/a)/180
       for (int k=0; k<a; k++) {
          xx=(r-rr)*Math.cos(t*k)+x; //(g) 次のx座標
          yy=(r-rr)*Math.sin(t*k)+y; //(g) 次のy座標
          rcircle(g,nn-1,xx,yy,rr);  //    再帰呼出し
       }
    } //end rcircle
 } //end Circle
