/* A basic extension of the java.applet.Applet class */ import java.awt.*; import java.applet.*; public class Applet1 extends Applet { //{{DECLARE_CONTROLS java.awt.Button continueButton; java.awt.Button restartButton; java.awt.Button tellButton1; java.awt.Button tellButton2; //}} DPoint a,b,c; DPoint l,m,n; DPoint p,q,r; DPoint h; DPoint d,e,f; DPoint y; DLine sideab,sidebc,sideca,altap,altbq,altcr; DLine eh, ol, lm, mn, nl,om, on, ah,dh,oh,dm; DLine hp, ak, bk, ok, xp, hk; DPoint center,o,k; DLine ao, ay, cy, by, bh, ch; double radius, s, nineptRadius; int state; Font font; int fsize; public void init() { // This code is automatically generated by Visual Cafe when you add // components to the visual environment. It instantiates and initializes // the components. To modify the code, only use code syntax that matches // what Visual Cafe can generate, or Visual Cafe may be unable to back // parse your Java file into its visual environment. //{{INIT_CONTROLS setLayout(null); setBackground(new Color(12632256)); continueButton = new java.awt.Button(); continueButton.setLabel("continue"); continueButton.reshape(108,264,60,28); continueButton.setBackground(new Color(16776960)); add(continueButton); restartButton = new java.awt.Button(); restartButton.setLabel("restart"); restartButton.reshape(12,264,60,28); restartButton.setBackground(new Color(16776960)); add(restartButton); tellButton1 = new java.awt.Button(); tellButton1.setLabel("P on circle center X radius r/2"); tellButton1.setVisible(false); tellButton1.reshape(12,228,192,28); tellButton1.setBackground(new Color(16776960)); add(tellButton1); tellButton2 = new java.awt.Button(); tellButton2.setLabel("D on circle center X radius r/2"); tellButton2.setVisible(false); tellButton2.reshape(228,228,192,28); tellButton2.setBackground(new Color(16776960)); add(tellButton2); //}} state = 1; font = new Font("TimesRoman", Font.PLAIN, 12); fsize = 2+font.getSize(); a = new DPoint(40.0,20.0,"A"); b = new DPoint(270.0,20.0,"B"); c = new DPoint(120.0,150.0,"C"); sideab = new DLine(a,b); sidebc = new DLine(b,c); sideca = new DLine(c,a); l = sideab.midpoint(); m = sidebc.midpoint(); n = sideca.midpoint(); l.label = "L"; m.label = "M"; n.label = "N"; r = sideab.footalt(c); p = sidebc.footalt(a); q = sideca.footalt(b); p.label = "P"; q.label = "Q"; r.label = "R"; altap = new DLine(a,p); altbq = new DLine(b,q); altcr = new DLine(c,r); h = altap.intersect(altbq); h.label = "H"; d = new DLine(a,h).midpoint(); e = new DLine(b,h).midpoint(); f = new DLine(c,h).midpoint(); d.label = "D"; e.label = "E"; f.label = "F"; center = l.circumcenter(m,n); center.label = "X"; o = a.circumcenter(b,c); o.label = "O"; radius = center.dist(l); s = o.dist(a); eh = new DLine(e,h); om = new DLine(o,m); lm = new DLine(l,m); mn = new DLine(m,n); nl = new DLine(n,l); ol = new DLine(o,l); on = new DLine(o,n); ah = new DLine(a,h); dh = new DLine(d,h); oh = new DLine(o,h); dm = new DLine(d,m); hp = new DLine(h,p); // Read the proof to see why this next thing works. k = hp.lambdapoint(2.0); k.label = "K"; ak = new DLine(a,k); bk = new DLine(b,k); ok = new DLine(o,k); xp = new DLine(center,p); hk = new DLine(h,k); ao = new DLine(a, o); y = ao.lambdapoint(2.0); y.label = "Y"; ay = new DLine(a, y); by = new DLine(b, y); cy = new DLine(c, y); bh = new DLine(b,h); ch = new DLine(c,h); nineptRadius = center.dist(l); } public void draw1(Graphics g) { g.setColor(Color.black); g.setFont(font); sideab.Show(g); sidebc.Show(g); sideca.Show(g); a.Show(g,7); b.Show(g,1); c.Show(g,4); g.setColor(Color.red); g.drawString("L,M,N are the midpoints of the sides.",300,20); l.Show(g,0); m.Show(g,3); n.Show(g,5); g.setColor(Color.blue); g.drawString("P,Q,R are the feet of the altitudes.",300, 20+fsize); p.Show(g,3); q.Show(g,5); r.Show(g,0); altap.Show(g); altbq.Show(g); altcr.Show(g); g.setColor(Color.blue); h.Show(g,7); g.drawString("H is the orthocenter.",300,20+2*fsize); g.setColor(Color.cyan); d.Show(g,1); e.Show(g,7); f.Show(g,3); g.drawString("D,E,F are the midpoints of AH, BH and CH.",300,20+3*fsize); g.setColor(Color.magenta); o.Show(g,0); g.drawOval( (int)(o.x-s),(int)(o.y-s),(int)(2.0*s),(int)(2.0*s)); g.drawString("O is the circumcenter. Let r be the ",300,20+4*fsize); center.Show(g,0); g.drawString("radius of the circumcircle. X is the midpoint of OH.",300, 20+5*fsize); } public void draw2(Graphics g){ draw1(g); g.setColor(Color.red); g.drawString("The circle with center X and radius r/2 ", 300, 20+6*fsize); g.drawString("passes through P, Q, R, D, E, F.", 300, 20 + 7 * fsize); } public void draw21(Graphics g){ draw2(g); g.setColor(Color.red); sideca.Show(g); altbq.Show(g); sidebc.Show(g); ak.Show(g); k.Show(g,4); bk.Show(g); g.setColor(Color.black); g.drawString("Angle CAP = angle CBQ because each is complementary to angle C.",10,180); g.drawString("Angle CAK = angle CBK because both cut off arc CK.",10,180+fsize); g.drawString("Therefore angle CBK = angle CBH.", 10, 180+2*fsize); g.drawString("Therefore triangles CBK and CBH are congruent, so HP=PK. Thus P is on the circle by the lemma.",10,180+3*fsize); } public void draw22(Graphics g){ draw2(g); g.setColor(Color.black); g.drawString("D is by definition the midpoint of AH,", 10, 180); g.drawString("so D is on the circle by the lemma.", 10, 180+fsize); } public void draw3(Graphics g){ draw2(g); g.setColor(Color.blue); y.Show(g,3); ay.Show(g); g.setColor(Color.green); by.Show(g); ch.Show(g); bh.Show(g); cy.Show(g); g.setColor(Color.green); g.drawString("Let AO meet the circumcircle at Y.", 300, 20 + 8 * fsize); g.drawString("Then YBHC is a parallelogram.", 300, 20 + 9 * fsize); } public void draw4(Graphics g){ draw3(g); g.setColor(Color.black); g.drawString("So diagonals YH and BC bisect each other at M.", 300, 20 + 10 * fsize); g.drawString("Then, by the lemma, M is on the circle center X,", 300, 20 + 11 * fsize); g.drawString("radius r/2. Likewise, so are L and N.", 300, 20 + 12 * fsize); g.drawOval( (int)(center.x-nineptRadius),(int)(center.y-nineptRadius),(int)(2.0*nineptRadius),(int)(2.0*nineptRadius)); } public void draw31(Graphics g){ draw3(g); g.setColor(Color.black); g.drawString("Angle ACY is right since AY is a diameter of circle ACY.",10, 180); g.drawString("Thus YC || BH. Also angle ABY is right, so YB || BH.", 10, 180 + fsize); } public boolean action(Event e, Object o){ if(e.target == continueButton && state == 1){ state = 2; tellButton1.show(); tellButton2.show(); } else if(e.target == restartButton){ state = 1; tellButton1.setLabel("P on circle center X radius r/2"); tellButton2.setLabel("D on circle center X radius r/2"); tellButton1.hide(); tellButton2.hide(); } else if(e.target == tellButton1 && (state == 2 || state == 21 || state == 22)){ state = 21; } else if(e.target == tellButton2&& (state == 2 || state == 21 || state == 22)){ state = 22; } else if(e.target == continueButton&& (state == 2 || state == 21 || state == 22)){ state = 3; tellButton2.hide(); tellButton1.show(); tellButton1.setLabel("YBHC is a parallelogram"); } else if(e.target == tellButton1 && state == 3){ state = 31; } else if(e.target == continueButton && (state == 3 || state == 31)){ state = 4; tellButton1.hide(); } repaint(); return true; } public void paint(Graphics g){ switch(state){ case 1: draw1(g); break; case 2: draw2(g); break; case 21: draw21(g); break; case 22: draw22(g); break; case 3: draw3(g);break; case 31: draw31(g);break; case 4: draw4(g); break; } } }