import java.awt.*; import java.applet.Applet; import java.awt.event.*; public class graafikakomponent extends Applet implements ActionListener{ Button nupp = new Button("Liigu!"); Button nupp2 = new Button("Kurb :("); Button nupp3 = new Button("Silm ;)"); public graafikakomponent(){ add(nupp); nupp.addActionListener(this); add(nupp2); nupp2.addActionListener(this); add(nupp3); nupp3.addActionListener(this); } public void paint(Graphics g){ int x=100; int y=150 ; g.setColor(Color.black); g.drawOval(x-100, y-100, 200, 200); g.fillOval(x-60, y-60, 40, 40); g.fillOval(x+20, y-60, 40, 40); g.drawLine(x-1, y-10, x, y+30); g.drawLine(x, y-10, x, y+30); g.drawLine(x+1, y-10, x, y+30); g.drawArc(x-50, y-50, 100, 100, 0, -180); } public void actionPerformed(ActionEvent e){ if(e.getSource()==nupp){ joonistaLiigu(); } if(e.getSource()==nupp2){ joonistaKurb(); } if(e.getSource()==nupp3){ joonistaSilm(); } } void joonistaLiigu(){ Graphics g=this.getGraphics(); for(int x=100; x<300; x=x+2){ int y=150; g.setColor(Color.black); g.drawOval(x-100, y-100, 200, 200); g.fillOval(x-60, y-60, 40, 40); g.fillOval(x+20, y-60, 40, 40); g.drawLine(x-1, y-10, x, y+30); g.drawLine(x, y-10, x, y+30); g.drawLine(x+1, y-10, x, y+30); g.drawArc(x-50, y-50, 100, 100, 0, -180); try{Thread.sleep(50);}catch(Exception s){} g.setColor(Color.white); g.fillRect(0, 0, 1500, 1500); } for(int x=300; x>100; x=x-2){ int y=150; g.setColor(Color.black); g.drawOval(x-100, y-100, 200, 200); g.fillOval(x-60, y-60, 40, 40); g.fillOval(x+20, y-60, 40, 40); g.drawLine(x-1, y-10, x, y+30); g.drawLine(x, y-10, x, y+30); g.drawLine(x+1, y-10, x, y+30); g.drawArc(x-50, y-50, 100, 100, 0, -180); try{Thread.sleep(50);}catch(Exception s){} g.setColor(Color.white); g.fillRect(0, 0, 1500, 1500); } int x=100; int y=150 ; g.setColor(Color.black); g.drawOval(x-100, y-100, 200, 200); g.fillOval(x-60, y-60, 40, 40); g.fillOval(x+20, y-60, 40, 40); g.drawLine(x-1, y-10, x, y+30); g.drawLine(x, y-10, x, y+30); g.drawLine(x+1, y-10, x, y+30); g.drawArc(x-50, y-50, 100, 100, 0, -180); } void joonistaKurb(){ Graphics g=this.getGraphics(); int x=100; int y=150 ; g.setColor(Color.black); g.drawOval(x-100, y-100, 200, 200); g.fillOval(x-60, y-60, 40, 40); g.fillOval(x+20, y-60, 40, 40); g.setColor(Color.white); g.drawLine(x-50, y-40, x, y-40); g.setColor(Color.black); g.drawLine(x-1, y-10, x, y+30); g.drawLine(x, y-10, x, y+30); g.drawLine(x+1, y-10, x, y+30); g.setColor(Color.white); g.drawArc(x-50, y-50, 100, 100, 0, -180); g.setColor(Color.black); g.drawArc(x-50, y+30, 100, 100, 0, 180); } void joonistaSilm(){ Graphics g=this.getGraphics(); int x=100; int y=150 ; g.setColor(Color.black); g.drawOval(x-100, y-100, 200, 200); g.setColor(Color.white); g.fillOval(x-60, y-60, 40, 40); g.setColor(Color.black); g.drawLine(x-50, y-40, x, y-40); g.drawLine(x-1, y-10, x, y+30); g.drawLine(x, y-10, x, y+30); g.drawLine(x+1, y-10, x, y+30); g.drawArc(x-50, y-50, 100, 100, 0, -180); } public static void main(String argumendid[]){ Frame f=new Frame(); f.add(new graafikakomponent()); f.setSize(400, 400); f.setVisible(true); } }