0% found this document useful (0 votes)
44 views

Ajp MP

This document is a micro project report on creating a simple text editor using Java Swing. It includes an introduction describing the components used like a JTextArea, JMenuBar and JMenuItems. The methods section lists the methods used like cut(), copy() and paste(). The program section includes the full Java code to implement the text editor with menus for file operations like open, save, print and edit operations like cut, copy and paste.

Uploaded by

Living Soul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Ajp MP

This document is a micro project report on creating a simple text editor using Java Swing. It includes an introduction describing the components used like a JTextArea, JMenuBar and JMenuItems. The methods section lists the methods used like cut(), copy() and paste(). The program section includes the full Java code to implement the text editor with menus for file operations like open, save, print and edit operations like cut, copy and paste.

Uploaded by

Living Soul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

A Micro Project Report On

“Simple Text Editor using Java Swing”

Under Subject:
Advanced Java

Submitted By:
Lad Gauri (51)
Class- CM5I Div- A

Department of Computer Technology


Sanjivani K. B. P Polytechnic, Kopargoan
2022-23

Prof. R. S. Patil Mr. G. N. Jorvekar


Subject Teacher Head of Department
MAHARASHTRA STATE BOARD OF TECHNICAL
EDUCATION

Certificate

This is to certify that Mr. / Ms. Lad Gauri Sanjay .

Roll No. ____51___ of Fifth Semester Diploma in COMPUTER TECHNOLOGY


of

S.K.B.P. POLYTECHNIC ,KOPARGAON

has completed the MicroProject work satisfactory in ADVANCED JAVA


PROGRAMMING for the academic year 2022 - 2023 as prescribed in the
MSBTE curriculum.

Place: Kopargoan Enrollment No. 2000340541 .

Date: _________________. Exam Seat No.: 314027 .

Subject Teacher HOD Department

R.S.Patil Mam G.N.Jorvekar Sir


Introduction

To create a simple text editor in Java Swing we will use a


JTextArea, a JMenuBar and add JMenu to it and we will add
JMenuItems. All the menu items will have actionListener to
detect any action.
There will be a menu bar and it will contain two menus
and a button:
1. File menu: Open,
Save,
Print,
New

2. Edit menu: Cut,


Copy,
Paste

3. Close

Methods used:
Cut()
Copy()
Paste()
Print()

We have used file reader and file writer for more


information on file reading and writing in Java.
Program
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 {
JTextArea t;
JFrame f;
editor()
{
f = new JFrame("editor");
try {
UIManager.setLookAndFeel
("javax.swing.plaf.metal.MetalLookAndFeel");
MetalLookAndFeel.setCurrentTheme(new OceanTheme());
}
catch (Exception e) {
}
t = new JTextArea();
JMenuBar mb = new JMenuBar();
JMenu m1 = new JMenu("File");
JMenuItem mi1 = new JMenuItem("New");
JMenuItem mi2 = new JMenuItem("Open");
JMenuItem mi3 = new JMenuItem("Save");
JMenuItem mi9 = new JMenuItem("Print");
mi1.addActionListener(this);
mi2.addActionListener(this);
mi3.addActionListener(this);
mi9.addActionListener(this);
m1.add(mi1);
m1.add(mi2);
m1.add(mi3);
m1.add(mi9);
JMenu m2 = new JMenu("Edit");
JMenuItem mi4 = new JMenuItem("cut");
JMenuItem mi5 = new JMenuItem("copy");
JMenuItem mi6 = new JMenuItem("paste");
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);
f.show();
}
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")) {
JFileChooser j = new JFileChooser("f:");
int r = j.showSaveDialog(null);
if (r == JFileChooser.APPROVE_OPTION) {
File fi = new File(j.getSelectedFile().getAbsolutePath());
Try{
FileWriter wr = new FileWriter(fi, false);
BufferedWriter w = new BufferedWriter(wr);
w.write(t.getText());
w.flush();
w.close();
}
catch (Exception evt) {
JOptionPane.showMessageDialog(f, evt.getMessage());
}
else
JOptionPane.showMessageDialog(f, "the user cancelled the
operation");
}
else if (s.equals("Print")) {
try {
t.print();
}
}
catch (Exception evt) {
JOptionPane.showMessageDialog(f, evt.getMessage());
}
}
else if (s.equals("Open")) {
JFileChooser j = new JFileChooser("f:");
int r = j.showOpenDialog(null);
if (r == JFileChooser.APPROVE_OPTION) {
File fi = new File(j.getSelectedFile().getAbsolutePath());
try {
String s1 = "", sl = "";
FileReader fr = new FileReader(fi);
BufferedReader br = new BufferedReader(fr);
sl = br.readLine();
while ((s1 = br.readLine()) != null) {
sl = sl + "\n" + s1;
}
t.setText(sl);
}
catch (Exception evt) {
JOptionPane.showMessageDialog(f, evt.getMessage());
}
}
else
JOptionPane.showMessageDialog(f, "the user cancelled the
operation");
}
else if (s.equals("New")) {
t.setText("");
}
else if (s.equals("close")) {
f.setVisible(false);
}
}
public static void main(String args[])
{
editor e = new editor();
}
}
Program Outputs:
Thank You!

You might also like