import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Joonis2 extends JApplet implements ActionListener{ int laius=40; JTextField tfLaius=new JTextField(String.valueOf(laius)); public Joonis2(){ add(tfLaius, BorderLayout.SOUTH); tfLaius.addActionListener(this); } public void actionPerformed(ActionEvent e){ laius=Integer.parseInt(tfLaius.getText()); repaint(); } public void paint(Graphics g){ super.paint(g); //Puhastab platsi g.drawRect(10, 20, laius, 30); } public static void main(String[] arg){ JFrame f=new JFrame("Joonis"); f.setSize(400, 300); f.getContentPane().add(new Joonis2()); f.setVisible(true); f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); } }