import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class animatsioon2 extends Applet implements ActionListener, Runnable{ Button pluss=new Button(" - "); Button miinus=new Button(" + "); int px=-15; int py=70; int kiirus=50; public animatsioon2(){ new Thread(this).start(); add(pluss, BorderLayout.NORTH); pluss.addActionListener(this); add(miinus, BorderLayout.NORTH); miinus.addActionListener(this); } public void paint(Graphics g){ int x=240; int y=70; /************* PÄIKE *************/ g.setColor(new Color(200,240,255)); if (px<=185){ g.fillOval(px-2, py+1, 35, 35);//päike }else{ g.fillOval(px-2, py-1, 35, 35);//päike } g.setColor(new Color(255,255,0)); g.fillOval(px, py, 35, 35);//päike /************* MEES *************/ g.setColor(new Color(240,240,240)); g.fillOval(x, y, 30, 40);//pea g.setColor(new Color(100,100,100)); g.drawOval(x, y, 30, 40);//pea x=x+15; g.drawLine(x,y+16,x, y+25);//nina g.fillOval(x-9,y+15,6, 3);//vasak silm g.fillOval(x+5,y+15,6, 3);//parem silm g.drawLine(x-3,y+30,x+3, y+30);//suu y=y+40; g.drawLine(x, y, x, y+5);//kael y=y+5; g.drawLine(x,y,x, y+40);//keha g.drawLine(x, y, x-20, y+35 );//vasak käsi g.drawLine(x, y, x+20, y+35 );//parem käsi y=y+40; g.drawLine(x, y, x-15, y+45 );//vasak jalg g.drawLine(x, y, x+15, y+45 );//parem jalg /************* MUU JAMA *************/ g.setColor(new Color(0,128,0)); g.fillRect(0, y+45, 400,300 );//maapind g.fillOval(100, y-90, 50, 105);//puu1 g.fillOval(30, y-90, 50, 105);//puu2 g.setColor(new Color(128,64,0)); g.fillRect(50, y+15, 10,30 );//tüvi1 g.fillRect(120, y+15, 10,30 );//tüvi2 } public void actionPerformed(ActionEvent e){ if(e.getSource()==pluss){ kiirus=kiirus+20; } if(e.getSource()==miinus){ kiirus=kiirus-20; } } public void update(Graphics g){paint(g);} public void run(){ while(true){ try{Thread.sleep(kiirus);} catch(Exception viga){} if(px<400){ px=px+2; if(px<=185){ py=py-1; }else{ py=py+1; } } repaint(); } } public static void main(String[] argumendid){ Frame aken=new Frame(); aken.add(new animatsioon2()); aken.setSize(400, 300); aken.setVisible(true); aken.setBackground(new Color(200,240,255)); aken.setResizable(false); aken.setLocation(300, 200); } }