import java.io.*; import java.net.*; import java.awt.*; import java.awt.event.*; public class TekstiUuring3 extends java.applet.Applet implements ActionListener, MouseListener{ FileDialog fd=new FileDialog(new Frame()); static final long serialVersionUID=1; Button nupp1=new Button("Vali fail"); Label silt1=new Label(); public TekstiUuring3(){ setLayout(new BorderLayout()); Panel alapaneel=new Panel(new BorderLayout()); alapaneel.add(nupp1, BorderLayout.WEST); alapaneel.add(silt1, BorderLayout.CENTER); add(alapaneel, BorderLayout.SOUTH); nupp1.addActionListener(this); addMouseListener(this); } public void paint(Graphics g){ if(silt1.getText().length()==0){return;} try{ BufferedReader failist=new BufferedReader(new FileReader(silt1.getText())); String rida=failist.readLine(); while(rida!=null){ String[] m=rida.split(" "); try{ int d=20; g.drawOval(Integer.parseInt(m[0])-d/2, Integer.parseInt(m[1])-d/2, d, d); }catch(Exception ex2){ex2.printStackTrace();} rida=failist.readLine(); } failist.close(); } catch(Exception ex){ ex.printStackTrace(); } } public void mousePressed(MouseEvent e){ if(silt1.getText().length()==0){return;} try{ PrintWriter faili=new PrintWriter(new FileWriter(silt1.getText(), true)); //lisab juurde faili.println(e.getX()+" "+e.getY()); faili.close(); repaint(); } catch(Exception ex){ ex.printStackTrace(); } } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void actionPerformed(ActionEvent e){ try{ if(e.getSource()==nupp1){ fd.setVisible(true); silt1.setText(fd.getDirectory()+File.separator+fd.getFile()); } }catch(Exception ex){ ex.printStackTrace(); } } public static void main(String[] arg){ Frame f=new Frame(); f.add(new TekstiUuring3()); f.setSize(500, 300); f.setVisible(true); f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } } ); } }