import java.io.*; import java.net.*; import java.awt.*; import java.awt.event.*; public class TekstiUuring2 extends java.applet.Applet implements ActionListener{ TextArea ta1=new TextArea(); TextArea ta2=new TextArea(); Button nupp1=new Button("Vali fail"); Button nupp2=new Button("Salvesta"); Button nupp3=new Button("Ava"); Button nupp4=new Button(); Button nupp5=new Button(); FileDialog fd=new FileDialog(new Frame()); static final long serialVersionUID=1; public TekstiUuring2(){ setLayout(new BorderLayout()); Panel keskpaneel=new Panel(new GridLayout(1, 2)); Panel alapaneel =new Panel(new GridLayout(1, 5)); keskpaneel.add(ta1); keskpaneel.add(ta2); alapaneel.add(nupp1); alapaneel.add(nupp2); alapaneel.add(nupp3); alapaneel.add(nupp4); alapaneel.add(nupp5); add(keskpaneel, BorderLayout.CENTER); add(alapaneel, BorderLayout.SOUTH); nupp1.addActionListener(this); nupp2.addActionListener(this); nupp3.addActionListener(this); nupp4.addActionListener(this); nupp5.addActionListener(this); } public void actionPerformed(ActionEvent e){ try{ if(e.getSource()==nupp1){ fd.setVisible(true); ta1.setText(fd.getDirectory()+File.separator+fd.getFile()); } if(e.getSource()==nupp2){ FileWriter fw=new FileWriter(ta1.getText()); String sisu=ta2.getText(); fw.write(sisu, 0, sisu.length()); fw.close(); } if(e.getSource()==nupp3){ char[] sisu=new char[(int)new File(ta1.getText()).length()]; FileReader fr=new FileReader(ta1.getText()); fr.read(sisu); fr.close(); ta2.setText(new String(sisu)); } if(e.getSource()==nupp4){ String aadress=ta1.getText(); if(aadress.startsWith("http://")){ System.getProperties().put("proxySet", "true"); System.getProperties().put("proxyHost", "cache.tlu.ee"); System.getProperties().put("proxyPort", "3128"); BufferedReader lugeja=new BufferedReader(new InputStreamReader( new URL(aadress).openStream())); ta2.setText(""); String rida=lugeja.readLine(); while(rida!=null){ ta2.append(rida+"\n"); rida=lugeja.readLine(); } lugeja.close(); } else { ta2.setText("Pole veebiaadress"); } } }catch(Exception ex){ ex.printStackTrace(); } } public static void main(String[] arg){ Frame f=new Frame(); f.add(new TekstiUuring2()); f.setSize(500, 300); f.setVisible(true); } }