import java.awt.*;
import java.awt.event.*;
import java.applet.*;




public class numerikus extends Applet implements ActionListener{
    int w,h,ix0,iy0;
    double ense,om0;
    Label se1,se2;
    CheckboxGroup radio1,radio2;
    Checkbox c1,c2,c3,c4,c5,c6,c7,c8;
    Checkbox d1,d2,d3;
    Scrollbar sb1,sb2;
    Panel p1,p2,p3;
    Graphics g;
    TextField tf;

    private void harmonikus(){}
    private void csillapitott_harmonikus(){}
    void Lissajous(){
	g.setColor(Color.red);
	g.drawLine(0,h/2+50,w,h/2+50);
	double x=0,y=0,x1=0,y1=0,t=0,dt=.001;

	while(t<100){
	    t+=dt;
	    x=Math.cos(t);y=Math.cos(sb1.getValue()*.1*t+(double)sb2.getValue()/180.*Math.PI);
	    if(t>2*dt&&Math.abs(y)<=1&&Math.abs(y1)<=1) g.drawLine((int)(w*.5*(x1+1)),(int)(h-(h-100)*.5*(y1+1)),(int)(w*.5*(x+1)),(int)(h-(h-100)*.5*(y+1)));
	    x1=x;y1=y;
	    
	}
	
    }
   


    private double amplitudo(double om){
	return 1./Math.sqrt((om0*om0-om*om)*(om0*om0-om*om)+4*ense*ense*om*om);
    }

    private double fazis(double om){
	if(om<om0){
	    return Math.atan(2*ense*om/(om0*om0-om*om));
	}else{
	    return Math.atan(2*ense*om/(om0*om0-om*om))+3.1415926;
	}
	
    }


    public boolean OK=false;
    public void elindit(){OK=true;}

    public void init(){
	p1=new Panel();
	add(p1);
	p1.setBackground(Color.white);
	p1.setLayout(new GridLayout(4,2));
	radio1=new CheckboxGroup();
	c1=new Checkbox("Harmonikus rezgőmozgás",radio1,false);
	c2=new Checkbox("Csillapított harmonikus rezgőmozgás",radio1,false);
	c3=new Checkbox("Kényszerrezgések",radio1,false);
	c4=new Checkbox("Lissajous-görbék",radio1,true);
	c5=new Checkbox("Hajítás közegellenállással",radio1,false);
	c6=new Checkbox("Matematikai inga",radio1,false);
	c7=new Checkbox("Kettős inga",radio1,false);
	c8=new Checkbox("Bolygómozgás",radio1,false);
	p1.add(c1);
	p1.add(c5);
	p1.add(c2);
	p1.add(c6);
	p1.add(c3);
	p1.add(c7);
	p1.add(c4);
	p1.add(c8);
	p2=new Panel();
	add(p2);
	p2.setBackground(Color.white);
	p2.setLayout(new GridLayout(3,1));
	radio2=new CheckboxGroup();
	d1=new Checkbox("Explicit Euler-módszer",radio2,true);
	d2=new Checkbox("Középpont-módszer",radio2,false);
	d3=new Checkbox("Negyedrendű Runge-Kutta",radio2,false);
	p2.add(d1);
	p2.add(d2);
	p2.add(d3);
	tf=new TextField(20);
	add(tf);

	p3=new Panel();
	add(p3);
	p3.setBackground(Color.white);
	p3.setLayout(new GridLayout(2,2));

	om0=5.;
	sb1=new Scrollbar(Scrollbar.HORIZONTAL,10,1,10,33);
	sb1.setSize(100,10);
	p3.add(sb1);
	
	ense=sb1.getValue()*.1;
	int nh=new Double(ense).toString().length();
	if(nh>5) nh=5;
	se1=new Label("  frekvenciák aránya: "+new Double(ense).toString().substring(0,nh)+" ");p3.add(se1);

	sb2=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,183);
	sb2.setSize(100,10);
	p3.add(sb2);
	
	nh=new Double(sb2.getValue()).toString().length();
	if(nh>5) nh=5;
	se2=new Label("  fázis (fok) "+new Double(sb2.getValue()).toString().substring(0,nh)+" ");p3.add(se2);
	

	

	g=getGraphics();
	w=this.getBounds().width;
	h=this.getBounds().height-80;
	ix0=this.getBounds().x;
	iy0=this.getBounds().y;
	g.setColor(Color.yellow);
	g.fillRect(0,100,w,h-100);
	g.setColor(Color.blue);
	g.drawLine(0,h-1,w,h-1);
	g.drawLine(0,100,0,h-1);
	

	c4.addMouseListener(new MouseListener(){
		public void 	mouseClicked(MouseEvent e){
		    g.setColor(Color.yellow);
		    g.fillRect(0,100,w,h-100);
		    g.setColor(Color.blue);
		    g.drawLine(0,h,w,h);
		    g.drawLine(0,100,0,h);
		    Lissajous();
}
		// Invoked when the mouse button has been clicked (pressed and released) on a component.
		public void 	mouseEntered(MouseEvent e){}
 //Invoked when the mouse enters a component.
		public  void 	mouseExited(MouseEvent e){}
 //Invoked when the mouse exits a component.
		public void 	mousePressed(MouseEvent e){}
 //Invoked when a mouse button has been pressed on a component.
		public void 	mouseReleased(MouseEvent e){}


});


	sb1.addAdjustmentListener(new AdjustmentListener(){
		public void adjustmentValueChanged( AdjustmentEvent adje){
		    ense=sb1.getValue()*.1;
		    int nh=new Double(ense).toString().length();
		    if(nh>5) nh=5;
		    se1.setText("  frekvenciák aránya: "+new Double(ense).toString().substring(0,nh)+"  ");
		    g.setColor(Color.yellow);
		    g.fillRect(0,100,w,h-100);
		    g.setColor(Color.blue);
		    g.drawLine(0,h,w,h);
		    g.drawLine(0,100,0,h);
		    Lissajous();
		    
		}
		});

	sb2.addAdjustmentListener(new AdjustmentListener(){
		public void adjustmentValueChanged( AdjustmentEvent adje){
		    int nh=new Double(sb2.getValue()).toString().length();
		    if(nh>5) nh=5;
		    se2.setText("  fázis (fok) "+new Double(sb2.getValue()).toString().substring(0,nh)+" ");
		    g.setColor(Color.yellow);
		    g.fillRect(0,100,w,h-100);
		    g.setColor(Color.blue);
		    g.drawLine(0,h,w,h);
		    g.drawLine(0,100,0,h);
		    Lissajous();
		    
		}
		});


    }

    public void actionPerformed(ActionEvent ae){}

    public void stop(){}
    public void destroy(){}
    public void paint(Graphics g){
	w=this.getBounds().width;
	h=this.getBounds().height-80;
	ix0=this.getBounds().x;
	iy0=this.getBounds().y;
	g.setColor(Color.yellow);
	g.fillRect(0,100,w,h-100);
	g.setColor(Color.blue);
	g.drawLine(0,h-1,w,h-1);
	g.drawLine(0,100,0,h-1);
		    
	Lissajous();
		    
}
}





