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

public class Lift extends Applet implements ActionListener, Runnable{
  int m=50;    //lift1 krgus//
  int o=260;   //lift2 krgus//
  int s=80;    // korruse atribuut//
  int x=0;
  int y=0;
  Button nupp9=new Button(" 9 ");
  Button nupp8=new Button(" 8 ");
  Button nupp7=new Button(" 7 ");
  Button nupp6=new Button(" 6 ");
  Button nupp5=new Button(" 5 ");
  Button nupp4=new Button(" 4 ");
  Button nupp3=new Button(" 3 ");
  Button nupp2=new Button(" 2 ");
  Button nupp1=new Button(" 1 ");
 
  public Lift(){
 add(nupp1);
 add(nupp2);
 add(nupp3);
 add(nupp4);
 add(nupp5);
 add(nupp6);
 add(nupp7);
 add(nupp8);
 add(nupp9);
   
nupp1.addActionListener(this);
nupp2.addActionListener(this);
nupp3.addActionListener(this);
nupp4.addActionListener(this);
nupp5.addActionListener(this);
nupp6.addActionListener(this);
nupp7.addActionListener(this);
nupp8.addActionListener(this);
nupp9.addActionListener(this);
    }
  
  public void paint(Graphics g){
    g.setColor(Color.black);
	g.drawRect(50,50, 270, 270); //maja//
	int a=1;
	int b=30;
	g.drawLine(50, 80, 320, 80);   //sein 9
	g.drawLine(50, 110, 320, 110); //sein 8
	g.drawLine(50, 140, 320, 140); //sein 7
	g.drawLine(50, 170, 320, 170); //sein 6
	g.drawLine(50, 200, 320, 200); //sein 5
	g.drawLine(50, 230, 320, 230); //sein 4
	g.drawLine(50, 260, 320, 260); //sein 3
	g.drawLine(50, 290, 320, 290); //sein 2
	g.drawRect(50, m, 25, 30);		//lift1//
	g.drawRect(295, o, 25, 30);		//lift2//

    }

  
   
   public void run(){
		 while(m!=s||o!=s){
			
			try{Thread.sleep(300);} catch(Exception viga){}
			
				if(m>s) {
					x=m-s;
				} else {
					x=s-m; }
						
				if (o>s) {
					y=o-s;
				} else {
					y=s-o; }

             
				if(x<y) {
					if(m>s){
			    		m-=10;
					} else {
						if(m<s){
						m+=10;
					} else {
					if(m==s){}
					}
					}
				repaint();
			
				} else {

					if(o>s){			    
						o-=10;
					} else {
						if(o<s){
						o+=10;
					} else {
					  	if(o==s){
				}
				}
				repaint();
			    }
				}
								
			
	
		 
	
	if(m==s){
		}
	if(o==s){
		}
		
	}
	}


    
	
	public void actionPerformed(ActionEvent e) {
		try
		{
			
		if(e.getSource()==nupp9){
		s=50;
		
		new Thread(this).start();
		repaint();
		}
	
		if(e.getSource()==nupp8){
		s=80;
		
		new Thread(this).start();
		repaint();
		}

		if(e.getSource()==nupp7){
		s=110;
		
		new Thread(this).start();
		repaint();
		}
		if(e.getSource()==nupp6){
		s=140;
		
		new Thread(this).start();
		repaint();
		}
		if(e.getSource()==nupp5){
		s=170;
		
		new Thread(this).start();
		repaint();
		}
		if(e.getSource()==nupp4){
		s=200;
		
		new Thread(this).start();
		repaint();
		}
		if(e.getSource()==nupp3){
		s=230;
		
		new Thread(this).start();
		repaint();
		}
		if(e.getSource()==nupp2){
		s=260;
		
		new Thread(this).start();
		repaint();
		}
		if(e.getSource()==nupp1){
		s=290;
				
		new Thread(this).start();
		repaint();
		}

		}
		catch(NumberFormatException ex)
		{}
    
}
  
	
  public static void main(String argumendid[])throws Exception{
    Frame f=new Frame("Lift");
    f.add(new Lift());
    f.setSize(400, 400);
    f.setVisible(true);
  }
}
