 // 立方体の回転(スクロールバー) [Gr3d1.java](JDK 1.0.2)
 import java.applet.Applet;
 import java.awt.*;
 //!import java.awt.event.*;               // JDK 1.1
 //!public class Gr3d1 extends Applet
 //!       implements AdjustmentListener { // JDK 1.1
 public class Gr3d1 extends Applet {  //!
     Scrollbar scrX,scrY;     // Scrollbar
     Cube data = new Cube();  //(a*) 立方体の生成
     Color [] Col={Color.gray,Color.cyan,Color.green,
                   Color.red,Color.white,Color.orange,
                   Color.magenta,Color.pink};
  public void init() {      // ロード時の初期化メソッド
    setLayout(new BorderLayout());
    Panel p=new Panel();
    p.setLayout(new GridLayout(2,2,0,5)); // 行,列,hgap,vgap
    scrX=new Scrollbar(Scrollbar.HORIZONTAL,30,10,-90,100);//(b)
    scrY=new Scrollbar(Scrollbar.HORIZONTAL,30,10,-90,100);//(b)
    p.add(scrX);  // x軸 Scrollbar
    p.add(new Label(" X-Rotation (-90 .. +90)"));
    p.add(scrY);  // y軸 Scrollbar
    p.add(new Label(" Y-Rotation (-90 .. +90)"));
 //!add(p,"South");
    add("South",p);  //!
 //!scrX.addAdjustmentListener(this);      // JDK 1.1
 //!scrY.addAdjustmentListener(this);      // JDK 1.1
    setBackground(new Color(128,128,255)); // 背景色
  } //end init
 //! //========= JDK 1.1 イベント処理(スクロールバー) =========
 //! public void adjustmentValueChanged(AdjustmentEvent e) {
 //!    repaint();
 //! } //end adjustmentValueChanged
  //========= JDK 1.0.2 イベント処理(スクロールバー) =========
  public boolean handleEvent(Event e) {   //! イベントの処理
     repaint();         //!
     return true;       //!
  } //end handleEvent   //!
  //================= グラフィックスの表示 =================
  public void paint( Graphics g ) {
     for (int i=0; i<data.x.length; i++) {
        drawPG(g, data.x[i], data.y[i], data.z[i],
               150,200,Col[i]);
     }
     g.setColor(Color.yellow);
     g.drawString("X="+scrX.getValue()+" Y="+scrY.getValue(),
                   10,size().height-70);
    //!               10,getSize().height-70);
  } //end paint
  //=========== 多角形を描く xp:xの位置, yp:yの位置 ===========
  public void drawPG(Graphics g,double []x,double []y,
                     double []z,int xp,int yp,Color co) { //(c)
     double x1,y1,z0;
     int len=x.length;                         // 配列の大きさ
     int [] xx=new int [len];
     int [] yy=new int [len];
  //!final double RAD=Math.PI/180.0;           // ラジアンに変換
     double RAD=Math.PI/180.0;                 //!ラジアンに変換
     double a=scrX.getValue()*RAD;             //(d) x軸の回転角
     double b=scrY.getValue()*RAD;             //(d) y軸の回転角
     double sinA=Math.sin(a),sinB=Math.sin(b); // 関数の計算
     double cosA=Math.cos(a),cosB=Math.cos(b); // 関数の計算
     for (int i=0; i<len; i++) {
        x1= x[i]*cosB+z[i]*sinB;  //(e) x1の位置
        z0=-x[i]*sinB+z[i]*cosB;
        y1= y[i]*cosA-  z0*sinA;  //(e) y1の位置
        xx[i]=xp+(int)Math.rint(x1);
        yy[i]=yp-(int)Math.rint(y1);
     }
     g.setColor(co);             // 色の設定
     g.drawPolygon(xx,yy,len);   // 多角形 ワイヤフレーム
  } //end drawPG
 } //end Gr3d1
