import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class Pudel extends Applet implements ActionListener{ int vedelik=100; int pudeliMaht=1000; TextField tfVesi=new TextField("100"); TextField tfPudel=new TextField("1000"); public Pudel(){ add(new Label("Vedeliku kogus:")); add(tfVesi); add(new Label("Pudeli maht")); add(tfPudel); tfVesi.addActionListener(this); tfPudel.addActionListener(this); } public void actionPerformed(ActionEvent e){ vedelik=Integer.parseInt(tfVesi.getText().trim()); pudeliMaht=Integer.parseInt(tfPudel.getText().trim()); repaint(); } public void paint(Graphics g){ double pudeliAlgneMaht=1000; double koef=Math.pow(pudeliMaht/pudeliAlgneMaht, 1.0/3); int korgus=(int)(100*koef); int laius=(int)(50*koef); int alus=200; int vasak=30; int veeKorgus=vedelik*korgus/pudeliMaht; g.drawLine(vasak, alus-korgus, vasak, alus); g.drawLine(vasak, alus, vasak+laius, alus); g.drawLine(vasak+laius, alus, vasak+laius, alus-korgus); g.setColor(Color.blue); g.drawLine(vasak, alus-veeKorgus, vasak+laius, alus-veeKorgus); } public static void main(String argumendid[]){ Frame f=new Frame("Ruudu joonistamine"); f.setSize(300, 300); f.add(new Pudel()); f.setVisible(true); } }