import java.applet.Applet; import java.util.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class Linnad3 extends Applet implements MouseMotionListener{ Hashtable andmed=new Hashtable(); int hiireX, hiireY; public Linnad3(){ try{ addMouseMotionListener(this); BufferedReader sisse=new BufferedReader( new FileReader("linnadeandmed.txt")); String rida=sisse.readLine(); int suurimkaugus=-1; String asula="teadmata"; while(rida!=null){ String[] m=rida.split(" "); if(m.length==3){ System.out.println(m[0]+" koordinaatidega "+ m[1]+" ja "+m[2]); int x=Integer.parseInt(m[1]); int y=Integer.parseInt(m[2]); andmed.put(m[0], new int[]{x, y}); } rida=sisse.readLine(); } } catch(Exception ex){ex.printStackTrace();} } public void paint(Graphics g){ for(String linn: andmed.keySet()){ int[] koht=andmed.get(linn); int dx=koht[0]-hiireX; int dy=koht[1]-hiireY; int kaugus=(int)Math.sqrt(dx*dx+dy*dy); int toon=(kaugus<200)?kaugus:200; g.setColor(new Color(toon, toon, toon)); g.drawString(linn, koht[0], koht[1]); } } public void update(Graphics g){paint(g);} public void mouseMoved(MouseEvent e){ hiireX=e.getX(); hiireY=e.getY(); repaint(); } public void mouseDragged(MouseEvent e){} public static void main(String[] arg){ Frame f=new Frame(); f.add(new Linnad3()); f.setSize(700, 500); f.setVisible(true); } }