A Java Microproject
A Java Microproject
PROJECT REPORT ON
“Text Editor”
SUBMITTED BY
Mr. PREM CHUNIYAN [237]
Page 1
CERTIFICATE
This is certify that the project report entitled
“Text Editor”
SUBMITTED BY
Mr. Prem Chuniyan [237]
Place: - Kopargaon
Date: ----------------
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:
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.
• Java AWT and Swing Libraries: Ensure your project includes the necessary
Java AWT and Swing libraries for building the graphical user interface
components.
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");
// Text component
t = new JTextArea();
// Create a menubar
JMenuBar mb = new JMenuBar();
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");
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:");
if (r == JFileChooser.APPROVE_OPTION) {
try {
// Create a file writer
FileWriter wr = new FileWriter(fi, false);
// 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:");
// 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;
}
// 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:
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/
Page 13