• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Text Editor in Java Project

April 15, 2012 by ProjectsGeek 24 Comments

Text Editor in Java Project

Write a Awt application to develop a Text editor in Java .  It should implement following functions as menu options or functionality of Text editor  . 

  • New
  • Open
  • Save
  • Save As
  • Page Setup
  • Print
  • Exit
  • Delete
  • Cut
  • Copy
  • Paste
  • Find Next
  • Replace
  • Go To
  • Select All
 

Text Editor Java

 

Text edior in Java

 

 

 

Program Code for Java Text Editor :

 

 import java.awt.*;  
 import java.awt.event.*;  
 import java.io.*;  
 import java.util.*;  
 //Texteditor class starts here  
 class Texteditor extends Frame implements ActionListener  
 {  
 TextArea ta=new TextArea();  
 int i,len1,len,pos1;  
 String str="",s3="",s2="",s4="",s32="",s6="",s7="",s8="",s9="";  
 String months[]={"January","February","March","April","May","June","July","August","September","October","November","December"};  
 CheckboxMenuItem chkb=new CheckboxMenuItem("Word Wrap");  
 public Texteditor()  
 {  
 MenuBar mb=new MenuBar();  
 setLayout(new BorderLayout());  
 add("Center",ta);  
 setMenuBar(mb);  
 Menu m1=new Menu("File");  
 Menu m2=new Menu("Edit");  
 Menu m3=new Menu("Tools");  
 Menu m4=new Menu("Help");  
 mb.add(m1);  
 mb.add(m2);  
 mb.add(m3);  
 mb.add(m4);  
 MenuItem mi1[]={  
 new MenuItem("New"),new MenuItem("Open"),new MenuItem("Save")  
 ,new MenuItem("Save As"),new MenuItem("Page Setup")  
 ,new MenuItem("Print"),new MenuItem("Exit")  
 };  
 MenuItem mi2[]={new MenuItem("Delete"),new MenuItem("Cut"),  
 new MenuItem("Copy"),new MenuItem("Paste"),new MenuItem("Find"),  
 new MenuItem("Find Next"),new MenuItem("Replace"),  
 new MenuItem("Go To"),new MenuItem("Select All"),  
 new MenuItem("Time Stamp")};  
 MenuItem mi3[]={new MenuItem("Choose Font"),new MenuItem("Compile"),  
 new MenuItem("Run")};  
 MenuItem mi4[]={new MenuItem("Help Topics"),  
 new MenuItem("About Texteditor")};  
 for(int i=0;i<len1;i++ )="" <br=""> {  
 m1.add(mi1[i]);  
 mi1[i].addActionListener(this);  
 }  
 for(int i=0;i<len1;i++) {="" <br=""> m2.add(mi2[i]);  
 mi2[i].addActionListener(this);  
 }  
 m3.add(chkb);  
 chkb.addActionListener(this);  
 for(int i=0;i<len1;i++ )="" <br=""> {  
 m3.add(mi3[i]);  
 mi3[i].addActionListener(this);  
 }  
 for(int i=0;i<len1;i++) <br=""> {  
 m4.add(mi4[i]);  
 mi4[i].addActionListener(this);  
 }  
 MyWindowsAdapter mw=new MyWindowsAdapter(this);  
 addWindowListener(mw);  
 setSize(500,500);  
 setTitle("untitled notepad");  
 setVisible(true);  
 }  
 public void actionPerformed(ActionEvent ae)  
 {  
 String arg=(String)ae.getActionCommand();  
 if(arg.equals("New"))  
 { dispose();  
 Texteditor t11=new Texteditor();  
 t11.setSize(500,500);  
 t11.setVisible(true);  
 }  
 try {  
 if(arg.equals("Open"))  
 {  
 FileDialog fd1=new FileDialog(this,"Select File",FileDialog.LOAD);  
 fd1.setVisible(true);  
 String s4="";  
 s2=fd1.getFile();  
 s3=fd1.getDirectory();  
 s32=s3+s2;  
 File f=new File(s32);  
 FileInputStream fii=new FileInputStream(f);  
 len=(int)f.length();  
 for(int j=0;j<len1;j++ )="" <br=""> {  
 char s5=(char)fii.read();  
 s4=s4 + s5;  
 }  
 ta.setText(s4);  
 }  
 }  
 catch(IOException e)  
 {  
 }  
 try  
 {  
 if(arg.equals("Save As"))  
 {  
 FileDialog dialog1=new FileDialog(this,"Save As",FileDialog.SAVE);  
 dialog1.setVisible(true);  
 s7=dialog1.getDirectory();  
 s8=dialog1.getFile();  
 s9=s7+s8+".txt";  
 s6=ta.getText();  
 len1=s6.length();  
 byte buf[]=s6.getBytes();  
 File f1=new File(s9);  
 FileOutputStream fobj1=new FileOutputStream(f1);  
 for(int k=0;k<len1;k++) <br=""> {  
 fobj1.write(buf[k]);  
 }  
 fobj1.close();  
 }  
 this.setTitle(s8 +" Texteditor File");  
 }  
 catch(IOException e){}  
 if(arg.equals("Exit"))  
 {  
 System.exit(0);  
 }  
 if(arg.equals("Cut"))  
 {  
 str=ta.getSelectedText();  
 i=ta.getText().indexOf(str);  
 ta.replaceRange(" ",i,i+str.length());  
 }  
 if(arg.equals("Copy"))  
 {  
 str=ta.getSelectedText();  
 }  
 if(arg.equals("Paste"))  
 {  
 pos1=ta.getCaretPosition();  
 ta.insert(str,pos1);  
 }  
 if(arg.equals("Delete"))  
 {  
 String msg=ta.getSelectedText();  
 i=ta.getText().indexOf(msg);  
 ta.replaceRange(" ",i,i+msg.length());  
 msg="";  
 }  
 if(arg.equals("Select All"))  
 {  
 String strText=ta.getText();  
 int strLen=strText.length();  
 ta.select(0,strLen);  
 }  
 if(arg.equals("Time Stamp"))  
 {  
 GregorianCalendar gcalendar=new GregorianCalendar();  
 String h=String.valueOf(gcalendar.get(Calendar.HOUR));  
 String m=String.valueOf(gcalendar.get(Calendar.MINUTE));  
 String s=String.valueOf(gcalendar.get(Calendar.SECOND));  
 String date=String.valueOf(gcalendar.get(Calendar.DATE));  
 String mon=months[gcalendar.get(Calendar.MONTH)];  
 String year=String.valueOf(gcalendar.get(Calendar.YEAR));  
 String hms="Time"+" - "+h+":"+m+":"+s+" Date"+" - "+date+" "+mon+" "+year+" ";  
 int loc=ta.getCaretPosition();  
 ta.insert(hms,loc);  
 }  
 if(arg.equals("About Texteditor"))  
 {  
 AboutDialog d1=new AboutDialog(this,"About Texteditor");  
 d1.setVisible(true);  
 setSize(500,500);  
 }  
 }//Action pereformed end  
 public class MyWindowsAdapter extends WindowAdapter  
 {  
 Texteditor tt;  
 public MyWindowsAdapter(Texteditor ttt)  
 {  
 tt=ttt;  
 }  
 public void windowClosing(WindowEvent we)  
 {  
 tt.dispose();  
 }  
 }//Inner class winadapter end....  
 }//End of Texteditor class  
 public class balls  
 { public static void main(String args[])  
 {  
 Texteditor to=new Texteditor();  
 }  
 }  
 class AboutDialog extends Dialog implements ActionListener  
 {  
 AboutDialog(Frame parent,String title)  
 {  
 super(parent,title,false);  
 this.setResizable(false);  
 setLayout(new FlowLayout(FlowLayout.LEFT));  
 setSize(500,300);  
 }  
 public void actionPerformed(ActionEvent ae)  
 {  
 dispose();  
 }  
 }  

How to Run this Project :

  • Open Eclipse 
  • New Project 
  • Add new Class to project 
  • Paste Code in that class named Balls .
  • Run the Project …Enjoy..!!

 

Other Projects to Try:

  1. Java Programs
  2. Database connectivity in Java with MYSQL
  3. Applet Text Editor
  4. Text Editor Using Visual Basic
  5. Text or Screen Editor in C++ Language

Filed Under: Java Projects Tagged With: Java Projects

Reader Interactions

Comments

  1. Priyankae says

    August 23, 2015 at 12:24 pm

    Too many errors mainly in for loop. May be you have got a typo coz each for loop is starting with some weird symbols like =”” like this. Please correct that code and also initialize len1.

    Reply
    • ProjectsGeek says

      November 1, 2015 at 6:35 am

      Yes. Please replace those symbols “” with new one using your keyboard. This is issue with character values when you are copying text from website.

  2. gsingh says

    August 20, 2015 at 7:00 pm

    Hello.
    Sorry, but I didnt get how to correct the error which you mentioned above.
    Could you elaborate, or possible fix the code accordingly please?
    Still not able to run it, gives about a 100 errors.

    Reply
    • ProjectsGeek says

      August 23, 2015 at 5:34 am

      Could you please specify those errors, So that we can help you out.

  3. Rakib says

    April 25, 2015 at 3:31 pm

    where is len1 initialized here????? how will the for loop run????????

    Reply
    • ProjectsGeek says

      April 26, 2015 at 12:44 pm

      Yes there is some mistake in code. Len1 should be equal to mi1.length.

  4. benson says

    March 22, 2015 at 2:02 am

    hello projects geek, do you have any running project for stock monitoring system??
    please give me any links that can be of help.
    thanks.

    Reply
    • ProjectsGeek says

      March 28, 2015 at 2:58 pm

      Please check this link for stock monitoring system.

      https://projectsgeek.com/2014/05/stock-investing-management-system-project.html

  5. shiraj says

    February 18, 2015 at 8:04 am

    showing some errors on for loops

    Reply
    • ProjectsGeek says

      March 8, 2015 at 12:48 pm

      Kindly post the exact error message you are getting so that we can debug the code and help you.

« Older Comments
Newer Comments »

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy