import java.applet.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class Jooned2 extends Applet implements MouseListener, MouseMotionListener{ Vector hoidla=new Vector(); int algx, algy; int otsx, otsy; Graphics gr; public Jooned2(){ addMouseListener(this); addMouseMotionListener(this); } public void mousePressed(MouseEvent e){ algx=e.getX(); algy=e.getY(); otsx=algx; otsy=algy; gr=getGraphics(); gr.drawLine(algx, algy, otsx, otsy); gr.setXORMode(Color.white); } public void mouseReleased(MouseEvent e){ hoidla.addElement(new Joon(algx, algy, e.getX(), e.getY())); repaint(); } public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseDragged(MouseEvent e){ gr.drawLine(algx, algy, otsx, otsy); otsx=e.getX(); otsy=e.getY(); gr.drawLine(algx, algy, otsx, otsy); } public void mouseMoved(MouseEvent e){} public void paint(Graphics g){ Enumeration e=hoidla.elements(); while(e.hasMoreElements()){ Joon j=(Joon)e.nextElement(); g.drawLine(j.x1, j.y1, j.x2, j.y2); } } public static void main(String[] arg){ Frame f=new Frame(); f.add(new Jooned2()); f.setSize(300, 300); f.setVisible(true); } class Joon{ int x1, y1, x2, y2; Joon(int ux1, int uy1, int ux2, int uy2){ x1=ux1; y1=uy1; x2=ux2; y2=uy2; } } }