Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

A

PROJECT REPORT ON
“Text Editor”
SUBMITTED BY
Mr. PREM CHUNIYAN [237]

Under the guidance of


Prof . Mr. S.B. JADHAV

DEPARTMENT OF COMPUTER TECHNOLOGY


Sanjivani Rural Education Society’s

SANJIVANI K.B.P POLYTECHNIC

KOPARGAON : 423603,DIST: AHMEDNAGAR

Page 1
CERTIFICATE
This is certify that the project report entitled
“Text Editor”

SUBMITTED BY
Mr. Prem Chuniyan [237]

Of Fifth semester of Diploma in ‘Computer Technology’ institute of Sanjivani


K.B.P Polytechnic Kopargaon has submitted the Micro-project satisfactorily in
subject “AJP” for academic year 2023 to 2024 as prescribed in the curriculum.

Place: - Kopargaon

Date: ----------------

Subject Teacher HOD Principal


(S.B JADHAV) (G.N.Jorvekar) (A.R.Mirkar)

Page 2
INTRODUCTION

Welcome to our innovative text editor, meticulously crafted using the power of
Java's AWT and Swing components. This project aims to provide a robust and
user-friendly platform for all your text editing needs. Java AWT and Swing,
renowned for their versatility and flexibility, have been masterfully harnessed to
create an interactive and visually appealing text editing experience. Our text
editor offers a range of features, including document creation, editing,formatting,
and more. The Java AWT components form the backbone, facilitating user
interaction and the overall structure of the editor, while Swing components
elevate the aesthetics, ensuring an intuitive and visually pleasing interface. This
project showcases how Java's AWT and Swing can be combined to build a
sophisticated application that caters to the needs of both casual users and
professionals. Whether you're a writer, programmer, or student, our text editor is
designed to streamline your work and enhance your text editing experience

Problem Statement:

The project aims to develop a robust and feature-rich text editor application
using Java AWT and Swing components. The primary challenge lies in creating
a user-friendly, responsive, and versatile text editing platform that caters to the
needs of diverse users. Key objectives include implementing basic text editing
functions, such as creating, opening, saving, and editing files, as well as more
advanced features like syntax highlighting, code autocompletion, and
customizable themes. Specific challenges to address involve designing an
intuitive user interface, managing memory and performance efficiently, ensuring
cross-platform compatibility, and offering a user-customizable experience.
Additionally, the project seeks to explore the incorporation of plugins or
extensions for further extensibility and functionality. This text editor project
endeavors to illustrate how Java AWT and Swing components can be leveraged
to create a powerful and user-centric text editing solution.

Page 3
Hardware Requirements:

• Computer with at least 4 GB of RAM to ensure smooth performance.

• Dual-core processor or higher to provide reasonable processing power for


running the text editor efficiently.

• Display with a minimum resolution of 1366x768 to offer a comfortable


workspace for text editing and interaction with the application.

Software Requirements:

• Java Development Kit (JDK): You'll need the latest version of the JDK to
compile and run your Java AWT and Swing-based text editor.

• Integrated Development Environment (IDE): You can use popular Java


development environments like Eclipse, IntelliJ IDEA, or NetBeans to simplify
coding, debugging, and project management.

• Java AWT and Swing Libraries: Ensure your project includes the necessary
Java AWT and Swing libraries for building the graphical user interface
components.

• Operating System: The project should be compatible with common operating


systems such as Windows, macOS, and Linux.

Page 4
Source code:
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.awt.event.*;
Import javax.swing.plaf.metal.*;
import javax.swing.text.*;
class editor extends JFrame implements ActionListener {
// Text component
JTextArea t;

// Frame
JFrame f;

// Constructor editor()
{
// Create a frame f = new JFrame("editor");

try {
// Set metl look and feel

UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

// Set theme to ocean


MetalLookAndFeel.setCurrentTheme(new OceanTheme());
}
catch (Exception e) {
}

// Text component
t = new JTextArea();

// Create a menubar
JMenuBar mb = new JMenuBar();

// Create amenu for menu

Page 5
JMenu m1 = new JMenu("File");
// Create menu items
JMenuItem mi1 = new JMenuItem("New");
JMenuItem mi2 = new JMenuItem("Open");
JMenuItem mi3 = new JMenuItem("Save");
JMenuItem mi9 = new JMenuItem("Print");

// Add action listener


mi1.addActionListener(this); mi2.addActionListener(this);
mi3.addActionListener(this); mi9.addActionListener(this);

m1.add(mi1); m1.add(mi2); m1.add(mi3);


m1.add(mi9);

// Create amenu for menu


JMenu m2 = new JMenu("Edit");

// Create menu items


JMenuItem mi4 = new JMenuItem("cut");
JMenuItem mi5 = new JMenuItem("copy");
JMenuItem mi6 = new JMenuItem("paste");

// Add action listener


mi4.addActionListener(this); mi5.addActionListener(this);
mi6.addActionListener(this);

m2.add(mi4); m2.add(mi5); m2.add(mi6);

JMenuItem mc = new JMenuItem("close");

mc.addActionListener(this);

mb.add(m1); mb.add(m2);
mb.add(mc);

f.setJMenuBar(mb);
f.add(t);
f.setSize(500, 500);

Page 6
f.show();
}

// If a button is pressed
public void actionPerformed(ActionEvent e)
{
String s = e.getActionCommand();

if (s.equals("cut")) { t.cut(); }
else if (s.equals("copy")) { t.copy(); }
else if (s.equals("paste")) { t.paste(); }
else if (s.equals("Save")) {
// Create an object of JFileChooser class
JFileChooser j = new JFileChooser("f:");

// Invoke the showsSaveDialog function to show the save dialog


int r = j.showSaveDialog(null);

if (r == JFileChooser.APPROVE_OPTION) {

// Set the label to the path of the selected directory


File fi = new File(j.getSelectedFile().getAbsolutePath());

try {
// Create a file writer
FileWriter wr = new FileWriter(fi, false);

// Create buffered writer to write


BufferedWriter w = new BufferedWriter(wr);

// Write
w.write(t.getText());

w.flush();
w.close();
}
catch (Exception evt) {
JOptionPane.showMessageDialog(f, evt.getMessage());

Page 7
}
}
// If the user cancelled the operation else
JOptionPane.showMessageDialog(f, "the user cancelled the
operation");
}
else if (s.equals("Print")) {
try {
// print the file
t.print();
}
catch (Exception evt) {
JOptionPane.showMessageDialog(f, evt.getMessage());
}
}
else if (s.equals("Open")) {
// Create an object of JFileChooser class
JFileChooser j = new JFileChooser("f:");

// Invoke the showsOpenDialog function to show the save dialog


int r = j.showOpenDialog(null);

// If the user selects a file


if (r == JFileChooser.APPROVE_OPTION) {
// Set the label to the path of the selected directory
File fi = new File(j.getSelectedFile().getAbsolutePath());
try {
// String
String s1 = "", sl = "";

// File reader
FileReader fr = new FileReader(fi);

// Buffered reader
BufferedReader br = new BufferedReader(fr);

// Initilize sl
sl = br.readLine();

Page 8
// Take the input from the file
while ((s1 = br.readLine()) != null) {
sl = sl + "\n" + s1;
}

// Set the text


t.setText(sl);
}
catch (Exception evt) {
JOptionPane.showMessageDialog(f, evt.getMessage());
}
}
// If the user cancelled the operation
else
JOptionPane.showMessageDialog(f, "the user cancelled the
operation");
}
else if (s.equals("New"))
{
t.setText("");
}
else if (s.equals("close"))
{
f.setVisible(false);
}
}

// Main class
public static void main(String args[])
{
editor e = new editor();
}
}

Page 9
Here’s a list of the classes and packages used in the provided Java program:

Packages:

1. `java.awt.*`: Contains classes for creating graphical user interfaces.


2. `javax.swing.*`: Provides components and widgets for building Swing-based
GUI applications.
3. `java.io.*`: Includes classes for handling input and output operations.
4. `java.awt.event.*`: Provides classes for handling events in AWT.
5. `javax.swing.plaf.metal.*`: Used for setting the Metal look and feel.
6. `javax.swing.text.*`: Contains classes for handling text in Swing components.

Classes:
1. `Editor`: The main class that extends `JFrame` and implements
`ActionListener`.
2. `JFrame`: A class representing a top-level container for a GUI application.
3. `JTextArea`: A component for editing and displaying text.
4. `JMenuBar`: A menu bar for adding menus to a frame.
5. `JMenu`: A menu within a menu bar.
6. `JMenuItem`: An item within a menu.
7. `JFileChooser`: A file chooser dialog for selecting files.
8. `File`: Represents a file in the file system.
9. `FileWriter`: Writes character data to a file.
10. `BufferedWriter`: Buffers output for character streams.
11. `JOptionPane`: Displays standard dialogs for user interaction.
12. `ActionEvent`: Represents an event when an action occurs.
13. `FileReader`: Reads character data from a file.
14. `BufferedReader`: Buffers input for character streams.

These classes and packages are used to create a simple text editor GUI
application that allows users to open, edit, save, and print text files. It also
provides basic text editing functionality such as cut, copy, and paste.

Page 10
OUTPUT:

Page 11
OUTPUT:

Page 12
CONCLUSION:
In conclusion, our Java AWT and Swing-based text editor project has
successfully delivered a versatile and user-friendly platform for text editing. It
addresses the needs of users across various skill levels, offering essential features
and advanced functionalities like syntax highlighting and customizable themes.
This project serves as an illustration of how Java's AWT and Swing components
can be harnessed to create a powerful and intuitive text editing tool, contributing
to a more efficient and enjoyable coding experience.

Reference:
• Oracle Java Documentation: https://docs.oracle.com/en/java/

• Eclipse IDE: https://www.eclipse.org/

• IntelliJ IDEA: https://www.jetbrains.com/idea/

• NetBeans IDE: https://netbeans.apache.org/"

Page 13

You might also like