import java.awt.*; import java.applet.*; import java.lang.Math; public class R4 extends Applet{Frame f, g, ccc; turn tx; Canvas cv, cc; boolean plain=true; public void init() {p600.setup(); tx = new turn(); cv = new canvas(tx); cc = new matcan(tx, this); {Dimension d = size(); cv.resize(d.width, d.height-40);} add(cv); Button baux = new button(tx, this); add(baux); add(cc);} void expand(){remove(cc); remove(cv); cv=null; cc=null; plain = false; f = new vwx("Alpha", tx, 0, 1); f.show(); g = new vwx("Beta" , tx, 2, 3); g.show(); ccc = new Frame("CCC"); ccc.add(new matcan(tx, this)); ccc.show();} void paint(){if(plain) paintComponents(getGraphics()); else {f.paint(f.getGraphics()); g.paint(g.getGraphics());}}} class button extends Button{boolean pushed = false; turn tx; int i, j; R4 pop; button(turn Tx, R4 Pop) {super("Bang"); tx=Tx; pop = Pop;} public boolean action(Event e, Object z){ if(e.id == Event.ACTION_EVENT) {if(!pushed){pushed = true; pop.expand(); return true;}} else System.out.println("OOps:"+e.id+"..."+Event.ACTION_EVENT); return true;}} class matcan extends Canvas{turn tx; R4 pop; matcan(turn Tx, R4 Pop){tx = Tx; pop = Pop; resize(24, 24);} public void paint(Graphics g){System.out.println("Reportingxx"+g); for(int i=0; i<5; ++i) {g.drawLine(2+5*i, 2, 2+5*i, 22); g.drawLine(2, 2+5*i, 22, 2+5*i);}} public boolean mouseDown(Event evt, int x, int y){ if(x < 22 && y < 22) {tx.jig((x-2)/5, (y-2)/5); pop.paint();} return true;}} class canvas extends Canvas{turn tx; canvas(turn Tx){tx = Tx; setBackground(Color.black);} public void paint(Graphics g){p600.paint(g, tx, 0, 1);} } class vwx extends Frame{turn ty; int i, j; vwx(String s, turn Ty, int I, int J) {super(s); ty =Ty; resize(50, 50); i=I; j=J; setBackground(Color.black);} public void paint(Graphics g){System.out.println("c:"+getBackground()); super.paint(g); p600.paint(g, ty, i, j);} public void dispose(){System.out.println("Going!"); super.dispose();} // handle the WINDOW (and Scrollbar) events here public boolean handleEvent(Event e) { if ( e.id == Event.WINDOW_DESTROY ) // any kind of window destroy event { hide(); // hide the Frame dispose(); // tell windowing system to free resources return true; } // anything else, we use the default behavior: Frame.handleEvent() System.out.println("event code = "+e.id); return super.handleEvent(e); } } class turn { public float[][] way = new float[4][4]; float[][] vel = new float[4][4]; public turn(){for(int i=0; i<4; ++i) for(int j=0; j<4; ++j) {way[i][j] = (i==j)?1:0; vel[i][j] = 0;}} public float[][] rex(){float[][] v = new float[2][4]; for(int j=0; j<4; ++j){v[0][j]=way[0][j]; v[1][j]=way[1][j];} return v;} public float[][] rey(){float[][] v = new float[2][4]; for(int j=0; j<4; ++j){v[0][j]=way[2][j]; v[1][j]=way[3][j];} return v;} public void twist(){float[][] q = new float[4][4]; for(int j=0; j<4; ++j) for(int i=0; i<4; ++i) {float s = 0; for(int m=0; m<4; ++m) s += way[i][m]*vel[m][j]; q[i][j] = s;} for(int j=0; j<4; ++j) for(int i=0; i<4; ++i) way[i][j] += q[i][j]; for(int j=0; j<4; ++j) {for(int i=0; i<=j; ++i) {float p = dot(way[j], way[i]); if(i=4 | J>=4 | I==J) return; for(int j=0; j<4; ++j) for(int i=0; i<4; ++i) vel[i][j] = (float)((i==I && j==J)?-0.02:((i==J && j==I)?0.02:0)); twist();} private void pvec(float[] q) {for(int i=0; i