import javax.swing.*; import java.awt.event.*; import java.awt.datatransfer.*; import javax.swing.filechooser.FileFilter; import java.awt.*; import java.io.*; public class uus1 extends JApplet { static JDesktopPane looRaamiPaneel(){ JToolBar riba = new JToolBar("Tööriistariba"); final JButton a=new JButton("Ava1"); riba.add(a); riba.addSeparator(); final JButton c=new JButton("Salvesta1"); riba.add(c); riba.addSeparator(); riba.addSeparator(); riba.addSeparator(); riba.addSeparator(); final JButton b=new JButton("Ava2"); riba.add(b); riba.addSeparator(); final JButton d=new JButton("Salvesta2"); riba.add(d); JInternalFrame siseraam=new JInternalFrame("Redaktorike" ); JInternalFrame siseraam1=new JInternalFrame("Redaktor1",true, false, true, false); JInternalFrame siseraam2=new JInternalFrame("Redaktor2",true, false, true, false); final JTextArea tf= new JTextArea(); final JTextArea ta= new JTextArea(); siseraam1.getContentPane().add(tf); siseraam2.getContentPane().add(ta); siseraam.getContentPane().add (riba); JDesktopPane paneel=new JDesktopPane(); siseraam.setSize(790, 70); siseraam.setLocation(0,-30); siseraam.setVisible(true); paneel.add(siseraam); try{siseraam.setSelected(true);}catch (Exception e){} siseraam1.setSize(395, 480); siseraam1.setLocation(0,35); siseraam1.setVisible(true); paneel.add(siseraam1); try{siseraam1.setSelected(true);}catch (Exception e){} siseraam2.setSize(395, 480); siseraam2.setLocation(395, 35); siseraam2.setVisible(true); paneel.add(siseraam2); /****************************************************** Reageerib nupuvajutusele ja avab failiotsingu akna kust valitud tekstifaili sisu kopeeritakse ühte aknasse *******************************************************/ a.addActionListener(new ActionListener(){ public void actionPerformed (ActionEvent e) { if(e.getSource()==a){ //System.out.println("mõhh"); JFileChooser valija=new JFileChooser(new File(".")); valija.addChoosableFileFilter(new Pildifilter()); valija.showDialog(new JFrame(), "Ava"); System.out.println("Valiti "+valija.getSelectedFile()); try{ BufferedReader sisse=new BufferedReader( new FileReader(valija.getSelectedFile()) ); String tulemus=" "; for(String rida=sisse.readLine(); rida!=null; rida=sisse.readLine()){ tulemus=rida+tulemus+"\n"; } tf.setText(tulemus); //System.out.println(tulemus); sisse.close(); }catch(IOException viga){viga.printStackTrace();} } } }); //###################################################### b.addActionListener(new ActionListener(){ public void actionPerformed (ActionEvent e) { if(e.getSource()==b){ //System.out.println("mõhh"); JFileChooser valija2=new JFileChooser(new File(".")); valija2.addChoosableFileFilter(new Pildifilter()); valija2.showDialog(new JFrame(), "Ava"); System.out.println("Valiti "+valija2.getSelectedFile()); try{ BufferedReader sisse2=new BufferedReader( new FileReader(valija2.getSelectedFile()) ); String tulemus2=" "; for(String rida2=sisse2.readLine(); rida2!=null; rida2=sisse2.readLine()){ tulemus2=rida2+tulemus2+"\n"; } ta.setText(tulemus2); //System.out.println(tulemus); sisse2.close(); }catch(IOException viga){viga.printStackTrace();} } } }); /*************************************************** Salvestamisnuppude algus ****************************************************/ c.addActionListener(new ActionListener(){ public void actionPerformed (ActionEvent e) { if(e.getSource()==c){ //System.out.println("mõhh"); JFileChooser valija3=new JFileChooser(new File(".")); valija3.addChoosableFileFilter(new Pildifilter()); valija3.showDialog(new JFrame(), "Salvesta"); System.out.println("Valiti "+valija3.getSelectedFile()); try{ PrintWriter faili=new PrintWriter( new FileWriter(valija3.getSelectedFile())); faili.println(tf.getText()); faili.close(); }catch(IOException viga){viga.printStackTrace();} } } }); //#################################################### d.addActionListener(new ActionListener(){ public void actionPerformed (ActionEvent e) { if(e.getSource()==d){ //System.out.println("mõhh"); JFileChooser valija4=new JFileChooser(new File(".")); valija4.addChoosableFileFilter(new Pildifilter()); valija4.showDialog(new JFrame(), "Salvesta"); System.out.println("Valiti "+valija4.getSelectedFile()); try{ PrintWriter faili=new PrintWriter( new FileWriter(valija4.getSelectedFile())); faili.println(ta.getText()); faili.close(); }catch(IOException viga){viga.printStackTrace();} } } }); //#################################################### return paneel; } public void init(){ getContentPane().add(looRaamiPaneel()); } public static void main(String argumendid[]) throws Exception{ JFrame f=new JFrame("TekstiRedaktor"); f.setContentPane(looRaamiPaneel()); f.setSize(800, 550); f.setVisible(true); } } //************************************** class Pildifilter extends FileFilter{ public boolean accept(File f){ String failinimi=f.getName(); if(failinimi.endsWith(".txt")|failinimi.endsWith(".doc")) return true; else return false; } public String getDescription(){ return "Tekstifailid "; } } //**************************************