import java.awt.*; import java.applet.*; import java.applet.Applet; import java.awt.event.*; public class Inimene2 extends Applet implements ActionListener{ TextField tf=new TextField("0"); Button start=new Button("Start"); Button nupp=new Button("Muuda"); String s; boolean liigu=false; int liikumine=1; int algus; int kiirus=1; int total_x; int x=40; int y=80; int a=-1; int paigalv=0; int paigalp=0; public Inimene2(){ // NUPPUDE PANEEL Button nupp2=new Button("Inimese kiirus: "); nupp2.setEnabled(false); Panel paneel=new Panel(new GridLayout(1,4)); paneel.add(start); paneel.add(nupp2); paneel.add(tf); paneel.add(nupp); start.setActionCommand("start"); start.addActionListener(this); nupp.setActionCommand("kiirus"); nupp.addActionListener(this); add(paneel, BorderLayout.NORTH); } public void paint(Graphics g){ x=40; y=80; a=-1; paigalv=0; paigalp=0; algus=60; while(liigu==true){ total_x=algus+liikumine*kiirus; g.setColor(Color.black); g.drawOval(total_x-20,40,40,40); g.drawRect(total_x-10,70,20,60); g.drawLine(total_x,130,x,180);//jalgade kiirusega probleem! g.drawLine(total_x,130,y,180); try{Thread.sleep(50);}catch(Exception e){} g.setColor(Color.white); g.drawOval(total_x-20,40,40,40); g.drawRect(total_x-10,70,20,60); g.drawLine(total_x,130,x,180); g.drawLine(total_x,130,y,180); if(x<=total_x-20) paigalv=0; else if(x>=total_x+20) paigalv=1; if(y<=total_x-20) paigalp=0; else if(y>=total_x+20) paigalp=1; if(paigalv==0){x=x+2*kiirus;} else if(paigalv==1){x=x;} if(paigalp==0){y=y+2*kiirus;} else if(paigalp==1){y=y;} liikumine=liikumine+1; } } public void actionPerformed(ActionEvent e){ s=e.getActionCommand(); if(s=="kiirus") kiirus=Integer.parseInt(tf.getText().trim()); else if(s=="start") liigu=true; repaint(); } public static void main(String argumendid[]){ Frame f=new Frame("Inimene"); f.setSize(800,300); f.setBackground(Color.white); f.add(new Inimene2()); f.setVisible(true); } };