import java.awt.*; import java.applet.Applet; import java.awt.event.*; import java.math.*; public class billard extends Applet implements AdjustmentListener , ActionListener { Panel Bouton; Scrollbar Scr1= new Scrollbar(Scrollbar.HORIZONTAL,60,10,0,100); Scrollbar Scr2= new Scrollbar(Scrollbar.HORIZONTAL,500,1,0,1000); Scrollbar Reflex= new Scrollbar(Scrollbar.HORIZONTAL,1,1,1,15000); Scrollbar Tronca= new Scrollbar(Scrollbar.HORIZONTAL,63,1,0,251); Label Lab1=new Label("a="); Label Lab2=new Label("b="); Label Lab0=new Label("orientation droite au départ: y=ax+b"); Label Laba=new Label("1"); Label Labb=new Label("0"); Label Lab3=new Label("r="); Label Lab4=new Label("nombre de réflexion: r"); Label Labr=new Label("1"); Label Lab5=new Label("Options sur la troncature:"); Label Labt=new Label("65"); int x,y,xc,yc,tr,t,tr2,z,i,tx,ty,re; double a,b,R,l,m,n,d,xs1,xs2,ys1,ys2,x0,y0,a2,a3,a4,b4,a5,b5,p,q,xx,yx; double phi,theta; Button tronc,init; String Str1,Str2,Str3,Str4; public static Graphics offgraphics; public static Image offscreen; public void init() { tronc = new Button("troncature"); init = new Button("Incidence"); Bouton=new Panel(); Panel P0=new Panel(); Panel P1=new Panel(); Panel P2=new Panel(); Panel P3=new Panel(); Panel P4=new Panel(); Panel P5=new Panel(); Panel P6=new Panel(); Panel P7=new Panel(); Panel P8=new Panel(); setLayout(new BorderLayout()); GridLayout lm=new GridLayout(9,1,10,10); Bouton.setLayout(lm); R=125.00; //rayon xc=225;// centre du cercle yc=225; tr=0;tr2=0; z=1; Bouton.setBounds(20,20,100,30); P0.add(Lab0); P1.add(Lab1); P1.add(Laba); P1.add(Scr1); P2.add(Lab2); P2.add(Labb); P2.add(Scr2); P3.add(Lab5); P4.add(tronc); P5.add(Labt); P5.add(Tronca); P6.add(Lab4); P7.add(Lab3); P7.add(Labr); P7.add(Reflex); P8.add(init); Bouton.add(P0,"East"); Bouton.add(P1,"East"); Bouton.add(P2,"East"); Bouton.add(P3,"East"); Bouton.add(P4,"East"); Bouton.add(P5,"East"); Bouton.add(P6,"East"); Bouton.add(P7,"East"); Bouton.add(P8,"East"); add(Bouton,"East"); Scr1.addAdjustmentListener(this); Scr2.addAdjustmentListener(this); Reflex.addAdjustmentListener(this); Tronca.addAdjustmentListener(this); tronc.addActionListener(this); init.addActionListener(this); } public void actionPerformed(ActionEvent ext) { Object source= ext.getSource(); if(source==tronc) {tr=Math.abs(tr-1);z=1;repaint();} if(source==init) {i=1;z=1;repaint();} } public void paint(Graphics g) { update(g); } public void update(Graphics g) { // if (z==1){g.setColor(Color.gray);g.fillRect(0,0,getSize().width,getSize().height);} g.setColor(Color.green); // g.drawString("LE BILLARD CHAOTIQUE",150,500); g.setColor(Color.blue); g.fillOval(100,100,250,250); //centre en(225,225) rayon 125 g.setColor(Color.red); g.drawLine(225,100,225,350); g.drawLine(100,225,350,225); tx=Tronca.getValue(); // ty=225+tx; ty=100+tx; g.setColor(Color.gray); g.fillRect(80,400,380,500); g.setColor(Color.lightGray); if(tr==1){ g.fillRect(ty,100,280-tx,250); g.setColor(Color.green); g.drawLine(ty,117,ty,333);} a=(double)((Scr1.getValue()/10.0)-5); b=(double)(Scr2.getValue()-500); re=Reflex.getValue(); xx=10*a+b;yx=500*a+b; if (i==1){g.setColor(Color.red);i=0;g.drawLine(10,(int)(xx),500,(int)(yx));} Str1=String.valueOf(a); Str2=String.valueOf(b); Str3=String.valueOf(re); Str4=String.valueOf(tx); Labr.setText(Str3); Labt.setText(Str4); Laba.setText(Str1); Labb.setText(Str2); g.setColor(Color.yellow);// l x^2+m x+n=0 for(t=0;tty){xs2=ty;}if (xs1>ty){xs1=ty;}} ys1=a*xs1+b; ys2=a*xs2+b; theta=Math.atan(a)*180.0/Math.PI; // System.out.println(theta); phi=Math.atan((ys1-225)/(xs1-225))*180.0/Math.PI; // System.out.println(phi); // System.out.println(xs1-225); g.drawLine((int)xs1,(int)ys1,(int)xs2,(int)ys2); //trace les rayons g.drawLine((int)phi+225,(int)((theta-phi)*0.5)+500,(int)phi+225,(int)((theta-phi)*0.5)+500); //trace l'espace des phase p=Math.abs(xs2-x0); q=Math.abs(xs1-x0); if (p>q) {x0=xs2;y0=ys2;}//if ((tr2==1)||(xs1==ty)){tr2=0;}} else {x0=xs1;y0=ys1;} if(z==1){x0=xs1;y0=ys1;z=0;} if (x0==ty) {tr2=1;} a3=(y0-yc)/(x0-xc); a2=-(x0-xc)/(y0-yc);// la normale et la tangente au cercle a4=(a-a2)/(a3-a); b4=(a*y0+b-y0)/(a3-a); a4=-a4; // passage sur réflexion grâce à la parité a5=(a2+a4*a3)/(1+a4);// retour à l'ancien repère a->a4 b5=(y0-a2*x0+a4*y0-a4*a3*x0)/(1+a4); if(tr2==1){a4=a;b4=a*x0+b-y0;a4=-a4;a5=a4;b5=b4+y0-a4*x0;tr2=0;} a=a5;b=b5;} } public void adjustmentValueChanged(AdjustmentEvent evt) { z=1; repaint(); } public void destroy() { Scr1.removeAdjustmentListener(this); Scr2.removeAdjustmentListener(this); Reflex.removeAdjustmentListener(this); Tronca.removeAdjustmentListener(this); } }