{"id":722,"date":"2012-04-15T06:24:00","date_gmt":"2012-04-15T06:24:00","guid":{"rendered":"http:\/\/projectsgeek.com\/text-editor-in-java-project\/"},"modified":"2019-07-14T06:05:53","modified_gmt":"2019-07-14T00:35:53","slug":"text-editor-in-java-project","status":"publish","type":"post","link":"https:\/\/projectsgeek.com\/2012\/04\/text-editor-in-java-project.html","title":{"rendered":"Text Editor in Java Project"},"content":{"rendered":"<h1 dir=\"ltr\" style=\"text-align: center;\"><span style=\"font-family: georgia,palatino; font-size: x-large; color: #ff6600;\">Text Editor in Java Project<\/span><\/h1>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"text-align: justify;\"><span style=\"font-family: georgia,palatino; font-size: medium;\">Write a Awt application to develop a Text editor in Java .\u00a0 It should implement following functions as menu options or functionality of Text editor\u00a0 .<\/span>&nbsp;<\/p>\n<ul>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">New<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Open<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Save<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Save As<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Page Setup<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Print<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Exit<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Delete<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Cut<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Copy<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Paste<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Find Next<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Replace<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Go To<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Select All<\/span><\/li>\n<\/ul>\n<table cellspacing=\"0\" cellpadding=\"0\" align=\"center\" style=\"width:100%;\">\n<tbody>\n<tr>\n<td><span style=\"font-family: georgia,palatino; font-size: medium;\">\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td>\n<h2><span style=\"font-family: georgia,palatino; font-size: large; color: #ff6600;\">Text Editor Java<\/span><\/h2>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: georgia,palatino; font-size: medium;\"><div id='gallery-1' class='gallery galleryid-722 gallery-columns-1 gallery-size-thumbnail'><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='https:\/\/images.projectsgeek.com\/2012\/04\/Text-edior-in-Java.png'><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/images.projectsgeek.com\/2012\/04\/Text-edior-in-Java-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"Text edior in Java\" \/><\/a>\n\t\t\t<\/div><\/figure>\n\t\t<\/div>\n<\/p>\n<p><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"font-family: georgia,palatino; font-size: large; color: #ff6600;\">Program Code for Java Text Editor :<\/span><\/h2>\n<p>&nbsp;<\/p>\n<pre class=\"prettyprint\" title=\"Text Editor in Java Project\"><span style=\"font-family: georgia,palatino; font-size: medium;\"> import java.awt.*;  \r\n import java.awt.event.*;  \r\n import java.io.*;  \r\n import java.util.*;  \r\n \/\/Texteditor class starts here  \r\n class Texteditor extends Frame implements ActionListener  \r\n {  \r\n TextArea ta=new TextArea();  \r\n int i,len1,len,pos1;  \r\n String str=\"\",s3=\"\",s2=\"\",s4=\"\",s32=\"\",s6=\"\",s7=\"\",s8=\"\",s9=\"\";  \r\n String months[]={\"January\",\"February\",\"March\",\"April\",\"May\",\"June\",\"July\",\"August\",\"September\",\"October\",\"November\",\"December\"};  \r\n CheckboxMenuItem chkb=new CheckboxMenuItem(\"Word Wrap\");  \r\n public Texteditor()  \r\n {  \r\n MenuBar mb=new MenuBar();  \r\n setLayout(new BorderLayout());  \r\n add(\"Center\",ta);  \r\n setMenuBar(mb);  \r\n Menu m1=new Menu(\"File\");  \r\n Menu m2=new Menu(\"Edit\");  \r\n Menu m3=new Menu(\"Tools\");  \r\n Menu m4=new Menu(\"Help\");  \r\n mb.add(m1);  \r\n mb.add(m2);  \r\n mb.add(m3);  \r\n mb.add(m4);  \r\n MenuItem mi1[]={  \r\n new MenuItem(\"New\"),new MenuItem(\"Open\"),new MenuItem(\"Save\")  \r\n ,new MenuItem(\"Save As\"),new MenuItem(\"Page Setup\")  \r\n ,new MenuItem(\"Print\"),new MenuItem(\"Exit\")  \r\n };  \r\n MenuItem mi2[]={new MenuItem(\"Delete\"),new MenuItem(\"Cut\"),  \r\n new MenuItem(\"Copy\"),new MenuItem(\"Paste\"),new MenuItem(\"Find\"),  \r\n new MenuItem(\"Find Next\"),new MenuItem(\"Replace\"),  \r\n new MenuItem(\"Go To\"),new MenuItem(\"Select All\"),  \r\n new MenuItem(\"Time Stamp\")};  \r\n MenuItem mi3[]={new MenuItem(\"Choose Font\"),new MenuItem(\"Compile\"),  \r\n new MenuItem(\"Run\")};  \r\n MenuItem mi4[]={new MenuItem(\"Help Topics\"),  \r\n new MenuItem(\"About Texteditor\")};  \r\n for(int i=0;i&lt;len1;i++ )=\"\" &lt;br=\"\"&gt; {  \r\n m1.add(mi1[i]);  \r\n mi1[i].addActionListener(this);  \r\n }  \r\n for(int i=0;i&lt;len1;i++) {=\"\" &lt;br=\"\"&gt; m2.add(mi2[i]);  \r\n mi2[i].addActionListener(this);  \r\n }  \r\n m3.add(chkb);  \r\n chkb.addActionListener(this);  \r\n for(int i=0;i&lt;len1;i++ )=\"\" &lt;br=\"\"&gt; {  \r\n m3.add(mi3[i]);  \r\n mi3[i].addActionListener(this);  \r\n }  \r\n for(int i=0;i&lt;len1;i++) &lt;br=\"\"&gt; {  \r\n m4.add(mi4[i]);  \r\n mi4[i].addActionListener(this);  \r\n }  \r\n MyWindowsAdapter mw=new MyWindowsAdapter(this);  \r\n addWindowListener(mw);  \r\n setSize(500,500);  \r\n setTitle(\"untitled notepad\");  \r\n setVisible(true);  \r\n }  \r\n public void actionPerformed(ActionEvent ae)  \r\n {  \r\n String arg=(String)ae.getActionCommand();  \r\n if(arg.equals(\"New\"))  \r\n { dispose();  \r\n Texteditor t11=new Texteditor();  \r\n t11.setSize(500,500);  \r\n t11.setVisible(true);  \r\n }  \r\n try {  \r\n if(arg.equals(\"Open\"))  \r\n {  \r\n FileDialog fd1=new FileDialog(this,\"Select File\",FileDialog.LOAD);  \r\n fd1.setVisible(true);  \r\n String s4=\"\";  \r\n s2=fd1.getFile();  \r\n s3=fd1.getDirectory();  \r\n s32=s3+s2;  \r\n File f=new File(s32);  \r\n FileInputStream fii=new FileInputStream(f);  \r\n len=(int)f.length();  \r\n for(int j=0;j&lt;len1;j++ )=\"\" &lt;br=\"\"&gt; {  \r\n char s5=(char)fii.read();  \r\n s4=s4 + s5;  \r\n }  \r\n ta.setText(s4);  \r\n }  \r\n }  \r\n catch(IOException e)  \r\n {  \r\n }  \r\n try  \r\n {  \r\n if(arg.equals(\"Save As\"))  \r\n {  \r\n FileDialog dialog1=new FileDialog(this,\"Save As\",FileDialog.SAVE);  \r\n dialog1.setVisible(true);  \r\n s7=dialog1.getDirectory();  \r\n s8=dialog1.getFile();  \r\n s9=s7+s8+\".txt\";  \r\n s6=ta.getText();  \r\n len1=s6.length();  \r\n byte buf[]=s6.getBytes();  \r\n File f1=new File(s9);  \r\n FileOutputStream fobj1=new FileOutputStream(f1);  \r\n for(int k=0;k&lt;len1;k++) &lt;br=\"\"&gt; {  \r\n fobj1.write(buf[k]);  \r\n }  \r\n fobj1.close();  \r\n }  \r\n this.setTitle(s8 +\" Texteditor File\");  \r\n }  \r\n catch(IOException e){}  \r\n if(arg.equals(\"Exit\"))  \r\n {  \r\n System.exit(0);  \r\n }  \r\n if(arg.equals(\"Cut\"))  \r\n {  \r\n str=ta.getSelectedText();  \r\n i=ta.getText().indexOf(str);  \r\n ta.replaceRange(\" \",i,i+str.length());  \r\n }  \r\n if(arg.equals(\"Copy\"))  \r\n {  \r\n str=ta.getSelectedText();  \r\n }  \r\n if(arg.equals(\"Paste\"))  \r\n {  \r\n pos1=ta.getCaretPosition();  \r\n ta.insert(str,pos1);  \r\n }  \r\n if(arg.equals(\"Delete\"))  \r\n {  \r\n String msg=ta.getSelectedText();  \r\n i=ta.getText().indexOf(msg);  \r\n ta.replaceRange(\" \",i,i+msg.length());  \r\n msg=\"\";  \r\n }  \r\n if(arg.equals(\"Select All\"))  \r\n {  \r\n String strText=ta.getText();  \r\n int strLen=strText.length();  \r\n ta.select(0,strLen);  \r\n }  \r\n if(arg.equals(\"Time Stamp\"))  \r\n {  \r\n GregorianCalendar gcalendar=new GregorianCalendar();  \r\n String h=String.valueOf(gcalendar.get(Calendar.HOUR));  \r\n String m=String.valueOf(gcalendar.get(Calendar.MINUTE));  \r\n String s=String.valueOf(gcalendar.get(Calendar.SECOND));  \r\n String date=String.valueOf(gcalendar.get(Calendar.DATE));  \r\n String mon=months[gcalendar.get(Calendar.MONTH)];  \r\n String year=String.valueOf(gcalendar.get(Calendar.YEAR));  \r\n String hms=\"Time\"+\" - \"+h+\":\"+m+\":\"+s+\" Date\"+\" - \"+date+\" \"+mon+\" \"+year+\" \";  \r\n int loc=ta.getCaretPosition();  \r\n ta.insert(hms,loc);  \r\n }  \r\n if(arg.equals(\"About Texteditor\"))  \r\n {  \r\n AboutDialog d1=new AboutDialog(this,\"About Texteditor\");  \r\n d1.setVisible(true);  \r\n setSize(500,500);  \r\n }  \r\n }\/\/Action pereformed end  \r\n public class MyWindowsAdapter extends WindowAdapter  \r\n {  \r\n Texteditor tt;  \r\n public MyWindowsAdapter(Texteditor ttt)  \r\n {  \r\n tt=ttt;  \r\n }  \r\n public void windowClosing(WindowEvent we)  \r\n {  \r\n tt.dispose();  \r\n }  \r\n }\/\/Inner class winadapter end....  \r\n }\/\/End of Texteditor class  \r\n public class balls  \r\n { public static void main(String args[])  \r\n {  \r\n Texteditor to=new Texteditor();  \r\n }  \r\n }  \r\n class AboutDialog extends Dialog implements ActionListener  \r\n {  \r\n AboutDialog(Frame parent,String title)  \r\n {  \r\n super(parent,title,false);  \r\n this.setResizable(false);  \r\n setLayout(new FlowLayout(FlowLayout.LEFT));  \r\n setSize(500,300);  \r\n }  \r\n public void actionPerformed(ActionEvent ae)  \r\n {  \r\n dispose();  \r\n }  \r\n }  <\/span><\/pre>\n<h2><\/h2>\n<h2><span style=\"font-family: georgia,palatino; font-size: large; color: #ff6600;\">How to Run this Project :<\/span><\/h2>\n<ul>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Open Eclipse\u00a0<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">New Project\u00a0<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Add new Class to project\u00a0<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Paste Code in that class named Balls .<\/span><\/li>\n<li><span style=\"font-family: georgia,palatino; font-size: medium;\">Run the Project &#8230;Enjoy..!!<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Text Editor in Java Project Write a Awt application to develop a Text editor in Java .\u00a0 It should implement following functions as menu options or functionality of Text editor\u00a0 .&nbsp; New Open Save Save As Page Setup Print Exit Delete Cut Copy Paste Find Next Replace Go To Select All \u00a0 Text Editor Java [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[4],"tags":[36],"class_list":{"0":"post-722","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-java-project","7":"tag-javaprojects","8":"entry"},"_links":{"self":[{"href":"https:\/\/projectsgeek.com\/wp-json\/wp\/v2\/posts\/722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/projectsgeek.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/projectsgeek.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/projectsgeek.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/projectsgeek.com\/wp-json\/wp\/v2\/comments?post=722"}],"version-history":[{"count":0,"href":"https:\/\/projectsgeek.com\/wp-json\/wp\/v2\/posts\/722\/revisions"}],"wp:attachment":[{"href":"https:\/\/projectsgeek.com\/wp-json\/wp\/v2\/media?parent=722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/projectsgeek.com\/wp-json\/wp\/v2\/categories?post=722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/projectsgeek.com\/wp-json\/wp\/v2\/tags?post=722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}