import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; public class R_Editor{ int n; Frame f=new Frame("R_Editor "); Dialog d=new Dialog(f, "About"); Dialog d2=new Dialog(f, "Statistics"); FileDialog fd=new FileDialog(f,"Select file",0); FileDialog fd2=new FileDialog(f,"Save as",1); TextArea ta=new TextArea(); TextArea tastat=new TextArea(); MenuBar menuBar = new MenuBar(); Menu menu1 = new Menu("File"); MenuItem m1Open=new MenuItem("Open"); MenuItem m1Save=new MenuItem("Save as"); MenuItem m1Sep1=new MenuItem("-"); MenuItem m1Stat=new MenuItem("Statistics"); MenuItem m1Sep2=new MenuItem("-"); MenuItem m1Exit=new MenuItem("Exit"); Menu menu2 = new Menu("Help"); MenuItem m2About=new MenuItem("About"); public static void main(String argumendid[]){ new R_Editor(); } public R_Editor(){ f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); f.add(ta); menu1.add(m1Open); menu1.add(m1Save); menu1.add(m1Sep1); menu1.add(m1Stat); menu1.add(m1Sep2); menu1.add(m1Exit); menu2.add(m2About); menuBar.add(menu1); menuBar.add(menu2); f.setMenuBar(menuBar); f.setSize(500, 400); f.setLocation(150, 80); f.setVisible(true); tastat.setEditable(false); m1Open.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ fd.show(); String p=fd.getDirectory()+fd.getFile(); // int pl=p.length(); // String ext=p.substring(pl-3,pl); if(fd.getFile()!=null){ try{ BufferedReader FileR=new BufferedReader(new FileReader(p)); String s1=""; String s2=FileR.readLine(); while(s2!=null){ s1=s1+s2+"\n"; s2=FileR.readLine(); ta.setText(s1); } f.setTitle("R_Editor "+p); }catch(Exception e2){} } } }); m1Save.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ fd2.show(); String p2=fd2.getDirectory()+fd2.getFile(); if(fd2.getFile()!=null){ try{ PrintWriter FileW=new PrintWriter(new FileWriter(p2)); FileW.print(ta.getText()); FileW.close(); f.setTitle("R_Editor "+p2); }catch(Exception e2){} } } }); m1Stat.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ Button b=new Button("OK"); d2.add(tastat, BorderLayout.CENTER); d2.add(b, BorderLayout.SOUTH); d2.setResizable(false); d2.setSize(300, 200); String s4=ta.getText(); int s4l=s4.length(); int max=0; String maxstring=""; StringTokenizer stk=new StringTokenizer(s4, " "); String snt=stk.nextToken(); maxstring=snt; n=0; while(stk.hasMoreTokens()){ String snt2=stk.nextToken(); n=n+1; if(snt2.length()>max){ max=snt2.length(); maxstring=snt2; } } // String stm1=""; // String stm2="a"; // for(int i=1; i<=s4l; i++){ // stm1=s4.substring(i-1, i); // if(stm1==" " && stm1!=stm2){ // n=n+1; // } // stm2=stm1; // } String path=f.getTitle(); int pathl=path.length(); String st1="Path: "+path.substring(10,pathl); String st2="Size: "+s4l+" bytes"; String st3="Number of words: "+(n+1); String stmain=st1+"\n"+st2+"\n"+st3; tastat.setText(stmain); d2.setLocation(300, 250); d2.show(); b.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ d2.dispose(); } }); } }); m1Exit.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.exit(0); } }); m2About.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ Button b=new Button("Roman Somov, Inc."); d.add(b); d.setResizable(false); d.setSize(200, 100); d.setLocation(300, 250); d.show(); b.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ d.hide(); } }); } }); } }