import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Lift extends Applet implements ActionListener { int a=441; Button aa=new Button("9"); Button aa1=new Button("8"); Button aa2=new Button("7"); Button aa3=new Button("6"); Button aa4=new Button("5"); Button aa5=new Button("4"); Button aa6=new Button("3"); Button aa7=new Button("2"); Button aa8=new Button("1"); public Lift(){ setLayout(null); aa.setBounds(90, 65, 20, 20); aa1.setBounds(90, 115, 20, 20); aa2.setBounds(90, 165, 20, 20); aa3.setBounds(90, 215, 20, 20); aa4.setBounds(90, 265, 20, 20); aa5.setBounds(90, 315, 20, 20); aa6.setBounds(90, 365, 20, 20); aa7.setBounds(90, 415, 20, 20); aa8.setBounds(90, 465, 20, 20); add(aa); add(aa1); add(aa2); add(aa3); add(aa4); add(aa5); add(aa6); add(aa7); add(aa8); aa.addActionListener(this); aa1.addActionListener(this); aa2.addActionListener(this); aa3.addActionListener(this); aa4.addActionListener(this); aa5.addActionListener(this); aa6.addActionListener(this); aa7.addActionListener(this); aa8.addActionListener(this); } public void paint(Graphics g){ int y=40; for(int i=1; i<10; i++){ g.setColor(Color.black); g.drawRect(40, y, 10, 50); g.drawRect(65, y, 85, 50); g.drawRect(165, y, 35, 50); g.drawLine(50, y, 65, y); g.drawLine(150, y, 165, y); y=y+50; } g.drawRect(51, 440, 13, 50); g.drawRect(151, 440, 13, 50); g.drawRect(40, 490, 160, 50); g.drawRect(40, 20, 160, 20); } public void actionPerformed(ActionEvent e){ Graphics g=this.getGraphics(); g.setColor(Color.white); g.drawRect(51, 440, 13, 50); g.drawRect(151, 440, 13, 50); g.setColor(Color.black); g.drawLine(50, 440, 65 , 440); g.drawLine(150, 440, 165 , 440); g.drawLine(50, 490, 65 , 490); g.drawLine(150, 490, 165 , 490); g.drawRect(51, a, 13, 50); g.drawRect(151, 440, 13, 50); if(e.getSource()==aa){ for(; a>40; a=a-2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a>42){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } } if(e.getSource()==aa1){ if(a>90){ for(; a>90; a=a-2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a>92){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } }else{ for(; a<90; a=a+2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a<88){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } } } if(e.getSource()==aa2){ if(a>140){ for(; a>140; a=a-2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a>142){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } }else{ for(; a<140; a=a+2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a<138){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } } } if(e.getSource()==aa3){ if(a>190){ for(; a>190; a=a-2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a>192){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } }else{ for(; a<190; a=a+2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a<188){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } } } if(e.getSource()==aa4){ if(a>240){ for(; a>240; a=a-2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a>242){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } }else{ for(; a<240; a=a+2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a<238){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } } } if(e.getSource()==aa5){ if(a>290){ for(; a>290; a=a-2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a>292){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } }else{ for(; a<290; a=a+2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a<288){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } } } if(e.getSource()==aa6){ if(a>340){ for(; a>340; a=a-2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a>342){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } }else{ for(; a<340; a=a+2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a<338){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } } } if(e.getSource()==aa7){ if(a>390){ for(; a>390; a=a-2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a>392){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } }else{ for(; a<390; a=a+2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a<388){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } } } if(e.getSource()==aa8){ if(a>440){ for(; a>440; a=a-2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a>442){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } }else{ for(; a<440; a=a+2){ g.setColor(Color.black); g.drawRect(51, a, 13, 50); try{Thread.sleep(20);}catch(Exception viga){} if(a<438){ g.setColor(Color.white); g.drawRect(51, a, 13, 50); } } } } } public static void main(String Arg[]){ Frame f=new Frame(""); f.add(new Lift()); f.setSize(700,700); f.setVisible(true); f.setResizable(false); } }