import java.applet.Applet; import java.awt.*; import java.lang.*; import java.awt.event.*; public class Yks extends Applet implements MouseListener{ int x1, y1, x2, y2; double kaugus, pikkus=0; int[] x = new int[10]; int[] y = new int[10]; int i=0; public void init(){ addMouseListener(this); } public void paint(Graphics g){ g.setColor(Color.blue); g.fillRect(0, 0, getSize().width, getSize().height); } public void mousePressed(MouseEvent e){ x[i]=e.getX(); y[i]=e.getY(); System.out.println(i+" "+x[i]+" "+y[i]); Graphics g=getGraphics(); g.setColor(Color.red); g.drawLine(x[i]-2, y[i], x[i]+2, y[i]); g.drawLine(x[i], y[i]-2, x[i], y[i]+2); if (i==9){ for (int k=0; k<10; k++){ for (int j=k+1; j<10; j++){ kaugus=Math.round(Math.sqrt((x[j]-x[k])*(x[j]-x[k])+(y[j]-y[k])*(y[j]-y[k]))); if (kaugus>pikkus){ x1=x[j]; x2=x[k]; y1=y[j]; y2=y[k]; pikkus=kaugus; g.setColor(Color.black); } } } g.drawLine(x1, y1, x2, y2); } i++; } public void mouseReleased(MouseEvent e){ //Graphics g=getGraphics(); } public void mouseExited(MouseEvent e){ Graphics g=getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, getSize().width, getSize().height); } public void mouseDragged(MouseEvent e){} public void mouseMoved(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseClicked(MouseEvent e){} }