import java.awt.event.*; import java.awt.*; import java.io.*; import java.util.*; import java.net.URL; import java.applet.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.filechooser.FileFilter; public class Text extends MouseInputAdapter implements ActionListener{ JFrame f1=new JFrame("TeX"); Image logo=Toolkit.getDefaultToolkit().getImage(new File("c:/gynntext/abook.jpg").toString ()); JTextArea ta=new JTextArea(); JTextField tf= new JTextField(""); JLabel l=new JLabel(""); JLabel fn=new JLabel(" Failinimi"); /****** knopki *****/ ImageIcon save=new ImageIcon( new File("c:/gynntext/save.gif").toString ()); ImageIcon neww=new ImageIcon(new File("c:/gynntext/new.gif").toString ()); ImageIcon open=new ImageIcon(new File("c:/gynntext/open.gif").toString ()); ImageIcon exit=new ImageIcon(new File("c:/gynntext/exit.gif").toString ()); ImageIcon cut=new ImageIcon(new File("c:/gynntext/cut.gif").toString ()); ImageIcon copy=new ImageIcon(new File("c:/gynntext/copy.gif").toString ()); ImageIcon paste=new ImageIcon(new File("c:/gynntext/paste.gif").toString ()); JButton b1=new JButton(save); JButton b7=new JButton(neww); JButton b2=new JButton(open); JButton b3=new JButton(exit); JButton b4=new JButton(cut); JButton b5=new JButton(copy); JButton b6=new JButton(paste); JButton b8=new JButton(new ImageIcon(new File("c:/gynntext/delete.gif").toString ())); JButton b9=new JButton(new ImageIcon(Toolkit.getDefaultToolkit ().getImage (new File("c:/gynntext/find.gif").toString ()))); int font_size=15; String puffer; AudioClip lugu; File fz; File lastDirr=new File ("c:/"); JButton la1=new JButton(); Vector failid; String [] undoo=new String [11]; MenuBar mb; Menu menu[]; String otsitav=null ; JButton yes,no; boolean cancel_pressed=false ; JDialog d; public static void main(String args[])throws Exception { new Text(); } private Text() throws Exception { failid =new Vector(); f1.setLocation(25,25); JScrollPane sp=new JScrollPane(ta); f1.setIconImage(logo); f1.setSize(500,700); this.menu(); lugu=Applet.newAudioClip(new URL("file:"+new File("c:/gynntext/camera.wav").toString ())); ta.setBackground(Color.white ); ta.setSelectedTextColor(Color.white ); ta.setSelectionColor(Color.black ); tf.setBackground(Color.lightGray ); f1.getContentPane().setLayout(new BorderLayout()); f1.getContentPane().add(sp,BorderLayout.CENTER); Container c; f1.setBackground(Color.lightGray ); l.setBackground(Color.lightGray ); fn.setBackground(Color.lightGray ); l.setForeground( Color.black ); l.setFont(new Font ("x",Font.BOLD ,14 )); f1.getContentPane().add(c =new Container(),BorderLayout.NORTH); c.setLayout(new GridLayout(2,1)); Container cc,ccc; c.add (cc=new Container()); c.add (ccc=new Container()); cc.setLayout (new GridLayout(1,8)); ccc.setLayout (new GridLayout(1,2)); c.setBackground(Color.gray); c.setForeground(Color.black); cc.add(b7); cc.add(b2); cc.add(b1); cc.add (b8); cc.add (b9); cc.add(b4); cc.add(b5); cc.add(b6); ccc.add(fn); ccc.add(tf); c.setVisible(true); cc.setVisible(true); ccc.setVisible(true); Container con; f1.getContentPane().add(con=new Container (),BorderLayout.SOUTH); con.setLayout (new BorderLayout ()); con.add(l,BorderLayout.CENTER); con.setVisible (true); f1.setVisible(true); b1.addMouseListener(this); b7.addMouseListener(this); b2.addMouseListener(this); b4.addMouseListener(this); b5.addMouseListener(this); b6.addMouseListener(this); b9.addMouseListener(this); b8.addMouseListener(this); b1.setToolTipText("Save or save ass.. "); b2.setToolTipText("Open"); b4.setToolTipText("Cut"); b5.setToolTipText("Copy"); b6.setToolTipText("Paste"); b7.setToolTipText("New"); b8.setToolTipText("Delete"); b9.setToolTipText("Find"); tf.setEditable(false); ta.addMouseListener (this); f1.addWindowListener( new WindowAdapter(){ public void windowDeiconified(WindowEvent we1 ){ menu();} public void windowClosing(WindowEvent we ){ System.exit (0);} } ); } public void mousePressed(MouseEvent me){ if (me.getSource()==b2){ open();} if (me.getSource()==b1) { savee();} if (me.getSource()==b4) { cut(); } if (me.getSource()==b5){ copy(); } if (me.getSource()==b6){ paste();} if (me.getSource()==b7){ neww();} if (me.getSource()==b8){ delete();} if (me.getSource()==b9){ find();} if (me.getSource()==yes){ d.dispose(); savee(); if(!cancel_pressed){ System.exit (0) ;} } if (me.getSource()==no){ System.exit (0);} } void paneSisu(String s){ta.setText(s); } void loe(File fail) throws FileNotFoundException,IOException { String lopp; String jooksev=""; lopp=""; BufferedReader br=new BufferedReader(new FileReader(fail)); jooksev=br.readLine(); for (;jooksev!=null;jooksev=(br.readLine())) lopp+=jooksev+"\n"; paneSisu(lopp); } String kysiSisu(){ return ta.getText(); } void kirjuta(File failin) throws Exception { if (failin==null) throw new Exception ("Viga kirjutamisel ! "); String sisu=kysiSisu(); DataOutputStream ds=new DataOutputStream(new FileOutputStream(failin)); int i; for(i=0;i=0) {ta.setSelectionStart(koht+position); ta.setSelectionEnd(koht+position+sona.length()); position=position+koht+sona.length (); } else{ Dialog d=new Dialog (raam," Find next ") ; Label l=new Label ("Rohkem pole otsitavat stringi !"); d.setLayout (new BorderLayout ()); d.add (l,BorderLayout.NORTH ); Button ok=new Button (" OK "); d.add (ok,BorderLayout.SOUTH); d.setSize (200,120); d.setLocation (raam.getLocation ().x +150,raam.getLocation ().y +150); ok.addMouseListener (new HK(d)); d.addWindowListener (new Dialog_kuular(d)); d.show (); } } else { jutt=origin.substring (0,position); if(chG.getSelectedCheckbox().getLabel().equals ("up")){ if ((koht=jutt.lastIndexOf(sona))>=0) {ta.setSelectionStart(koht); ta.setSelectionEnd(koht+sona.length()); position=koht; } else{ Dialog d=new Dialog (raam," Find next ") ; Label l=new Label ("Rohkem pole otsitavat stringi !"); d.setLayout (new BorderLayout ()); d.add (l,BorderLayout.NORTH ); Button ok=new Button (" OK "); d.add (ok,BorderLayout.SOUTH); d.setSize (200,120); d.setLocation (raam.getLocation ().x +150,raam.getLocation ().y +150); ok.addMouseListener (new HK(d)); d.addWindowListener (new Dialog_kuular(d)); d.show (); } } } } public void textValueChanged(TextEvent te){ position=0 ; } } class Dialog_kuular extends WindowAdapter{ Dialog d; Dialog_kuular(Dialog dd){ d=dd;} public void windowClosing(WindowEvent we){d.dispose(); } } class Raamikuular extends WindowAdapter { Frame f; Raamikuular(Frame fr){f=fr;} public void windowClosing(WindowEvent we){ f.dispose () ; } } class HK extends MouseAdapter { Dialog d; HK(Dialog dd){d=dd;} public void mousePressed(MouseEvent me){ d.dispose (); } } class LaiendiFilter extends FileFilter { String l; String d; LaiendiFilter(String la,String des){ l=la ; d=des; } public boolean accept(File f){ boolean out; out=false ; if(f.isDirectory ()){out=true ;} if(f.toString () .endsWith ("."+l)){out=true ;} return out; } public String getDescription(){ return d; } public String getExtension(){ return l; } } class Filter extends FileFilter{ String des; String laiend; Filter(String l){laiend=l ; des="(*."+l+")"+"filezz" ; } public boolean accept(File f){ boolean o=false; if (f.isDirectory ()) {o=true;} if (f.getName ().endsWith ("."+laiend)) {o=true;} return o; } public String getDescription(){return des;} } /* Autorid .... */ /*class Graph extends Thread { JWindow f; Canvas c=new Canvas (); JFrame parent; Image pilt,mees,mees1; Graph(JFrame r) { parent=r; pilt=Toolkit.getDefaultToolkit ().getImage ("c:/gynntext/abook1.jpg"); mees=Toolkit.getDefaultToolkit ().getImage ("c:/gynntext/m2.gif"); mees1=Toolkit.getDefaultToolkit ().getImage ("c:/gynntext/m3.gif"); start (); } public void run(){ f=new JWindow (parent); f.setSize (300,300); f.getContentPane().add (c); f.setLocation (parent.getLocation().x+100, parent.getLocation().y+150 ); f.show(); this.paint (); } void paint(){ Graphics g=c.getGraphics (); g.drawImage (pilt,0,0,300,300,f ); int i=0,x,y=285; for(x=350;x>50;x-=1,i++){ g.setColor (new Color (53,254,248)); g.drawString ("Teostanud : #Gunnar & #Riho ",x,y); try{Thread.sleep (10);} catch(Exception e){} g.drawImage (pilt,0,0,300,300,f ); } g.drawString ("Teostanud : #Gunnar & #Riho ",x,y); try{Thread.sleep (3000);} catch(Exception e){} f.dispose(); } } */ class Graph extends Thread { JWindow f; Canvas c=new Canvas (); JFrame parent; Image pilt ; Graph(JFrame r) { parent=r; pilt=Toolkit.getDefaultToolkit ().getImage ("c:/gynntext/abook.jpg"); start (); } public void run(){ f=new JWindow (parent); f.setSize (300,300); f.getContentPane().add (c); f.setLocation (parent.getLocation().x+100, parent.getLocation().y+150 ); f.show(); this.paint (); } void paint(){ Graphics g=c.getGraphics (); g.drawImage (pilt,0,0,300,300,f ); int i=0,x,y=285; for(x=350;x>50;x-=1,i++){ g.setColor (new Color (53,254,248)); g.drawString ("Teostanud : #Gunn & #Riho & #Tanel ",x,y); try{Thread.sleep (10);} catch(Exception e){} g.drawImage (pilt,0,0,300,300,f ); } g.drawString ("Teostanud : #Gunn & #Riho & #Tanel ",x,y); try{Thread.sleep (3000);} catch(Exception e){} f.dispose(); } }