import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class Tekst2b extends Applet implements ActionListener{ TextField pikkus=new TextField(" 100 "); Button nupp=new Button(" OK "); public Tekst2b(){ add(pikkus); add(nupp); nupp.addActionListener(this); } public void actionPerformed(ActionEvent e){ int nr=Integer.parseInt(pikkus.getText().trim()); Graphics g=this.getGraphics(); g.setColor(Color.white); g.fillRect(0, 0, getSize().width, getSize().height); g.setColor(Color.black); g.drawRect(10, 50, nr, nr); } public static void main(String argumendid[]){ Frame f=new Frame("Ruudu joonistamine"); f.setSize(300, 300); f.add(new Tekst2b()); f.setVisible(true); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } }