import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.awt.Graphics; import java.awt.Color; public class Esimene extends Applet implements ActionListener{ public void paint(Graphics ekraan){ ekraan.setColor(Color.black); ekraan.drawLine(0, 40, 0, 160); ekraan.drawLine(0, 40, 120, 40); ekraan.drawLine(20, 40, 20, 160); ekraan.drawLine(0, 60, 120, 60); ekraan.drawLine(40, 40, 40, 160); ekraan.drawLine(0, 80, 120, 80); ekraan.drawLine(60, 40, 60, 160); ekraan.drawLine(0, 100, 120, 100); ekraan.drawLine(80, 40, 80, 160); ekraan.drawLine(0, 120, 120, 120); ekraan.drawLine(100, 40, 100, 160); ekraan.drawLine(0, 140, 120, 140); ekraan.drawLine(0, 160, 120, 160); ekraan.drawLine(120, 40, 120, 160); ekraan.drawLine(0, 160, 120, 160); } TextField raadius=new TextField(" "), summa=new TextField(" "); Button nupp=new Button(" Joonista ja arvuta ring "); Label valem=new Label("S=d/2*3.14="); public void init(){ add(raadius); add(nupp); add(valem); add(summa); nupp.addActionListener(this); } public void actionPerformed(ActionEvent e){ int nr=Integer.parseInt(raadius.getText().trim()); Graphics g=this.getGraphics(); g.setColor(Color.red); g.fillOval(1, 41, nr, nr); summa.setText((numbriks(raadius)/2)*3.14+""); paint(g); } int numbriks(TextField tf){ return Integer.parseInt(tf.getText().trim()); } }