import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Hiirevajutus2 extends Applet implements MouseListener, ActionListener{ int x=100; int y=100; int d=20; TextField tf1=new TextField(String.valueOf(d)); //Soovin saada juurde ruudu suuruse //määramise võimaluse public Hiirevajutus2(){ add(tf1); addMouseListener(this); tf1.addActionListener(this); } public void actionPerformed(ActionEvent e){ if(e.getSource()==tf1){ d=Integer.parseInt(tf1.getText()); repaint(); } } public void paint(Graphics g){ g.drawRect(x-d/2, y-d/2, d, d); } public void mousePressed(MouseEvent e){ x=e.getX(); y=e.getY(); repaint(); } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String[] argumendid){ Frame f=new Frame(); f.add(new Hiirevajutus2()); f.setSize(200, 200); f.setVisible(true); } }