Beruflich Dokumente
Kultur Dokumente
Submitted by:
DIVYA ARYA
Submitted to:
----------------
CONTENTS
1.
Acknowledgement
2.
Preface
3.
Chapter 1- Introduction
Modular description of the job
Features of Notepad
Steps in Noteoad
SOURCE CODE
9.
Conclusion
10.
11.
References
ACKNOWLEGEMENT
On the very outset of this report, I would like to extend my
sincere obligation towards all the personages who have helped
PREFACE
CHAPTER-1
INTRODUCTION OF
NOTEPAD
Notepad itself can now open and edit files of virtually any
size. If you want to view the source file of any web page,
Internet explorer for example will open notepad to show you the
source. If you do not have a text editor, you can use notepad
and print what you have written. If you want to write code for
HTML, JAVASCRIPT etc., notepad is very useful. And I certainly
have noticed that while taking some online courses in other
kinds of scripts, notepad is the editor of choice.
FEATURES OF NOTEPAD
1
Font Setting.
Printing facility.
requirements.
Also,
adding
to
our
additional
Hardware Requirements:
1
256 MB RAM
Software Requiremenrs:
1
JDK 1.6
Operating System :
1
Design Phase
Coding
Testing
CHAPTER-2
SYSTEM
REQIREMENTS AND
ANALYSIS
Context Diagram
Notepad
NOTEPAD
1.
Introduction
1.1. Purpose
The Software Requirements Specification (SRS)
will provide a detailed description of the requirements
for the Notepad. This SRS will allow for a complete
understanding of what is to be expected of the
Notepad to be constructed. The clear understanding
of the Notepad and its functionality will allow for the
correct software to be developed for the end user and
will be used for the development of the future stages
of the project. This SRS will provide the foundation
for the project. From this SRS, the Notepad can be
designed, constructed, and finally tested.
1.2
Scope :
The software product to be produced is a Notepad
which will be a text editor used for various
operations. The first subsystem is a File
system used to create a new file, edit a new or existing
file and exit from the text editor. The second subsystem is
system
1.4 Overview :
The SRS is organized into two main sections. The first
is the overall description and the second is the Specific
Requirements. The overall description will describe the
requirements of the HMS from a general high level
perspective. The Specific Requirements section will
describe in detail the requirements of the system.
2. The
Overall Description :
hostel.
2.1.2 Software Interfaces
The whole NOTEPAD is made using JAVA using
jdk1.6.
sections.
2.4
Formatting
Line wrapping.
3. Specific Requirements
This section contains all the software requirements at a level
of detail, that when combined with the system context
diagram, use cases, and use case descriptions, is sufficient
to enable designers to design a system to satisfy those
requirements, and testers to test that the system satisfies
those requirements.
3.1
External Interfaces
The Notepad will use the standard input/ output devices
for a personal computer. These include the following :
3.2
Keyboard
Mouse
Monitor
Printer(not mandatory)
Functional Requirements
Functional Requirements define the fundamental
actions that system must perform. The functional
requirements for the system are divided into three main
categories, student information system, room information
system and billing section. For further details, refer to use
cases.
1.
1.2
1.3 The
The system shall ask the user which file to open and
from
what location
1.5 The system shall shut down the notepad screen if the
2.
Editing
2.1
2.2
2.3
2.4
3.
Setting
3.1
Formatting
4.1
CHAPTER-3
SYSTEM DESIGN
Design of Notepad:
This notepad has four Menus in MenuBar viz. File, Edit,
Settings, Format. In each Menu we have MenuItems
like Cut, Copy, Paste, Select All, Line Wrap etc. The
notepad frame should look as follows :
Figure-3 : Class
Diagram of Notepad
CHAPTER-4
SYSTEM
DEVELOPMENT
CODING
Packages Imported :
1
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.util.*;
import java.awt.PrintJob.*;
Font
JMenuBar
JMenuItem
Frame
Choice
Button
JTextArea
FileReader
FileWriter
LineNumberReader
String Reader
String
FileReader
FileWriter
Font
Ss
Mynotepad
myfr
Interfaces Implemented:
ActionListener
KeyListener
class mynotepad
{
public static void main(String s[])
{
myfr f=new myfr("Kanika's
Notepad"); f.setSize(400,400);
f.setVisible(true);
f.setLocation(0,0);
}
}
Usag
e:
Myfr Class:
to Font etc.
I have also given the check box in menu item for
Linewrapping.
Code for Line
Wrapping:
if(item12.isSelected())
{
t1.setLineWrap(true);
}
else
{
t1.setLineWrap(false);
}
ActionListener,KeyListener
{
JTextArea t1;
static Font f;
JCheckBoxMenuItem
item12; String str=getTitle();
myfr(String title)
{
super(title);
t1=new JTextArea();
getContentPane().setLayout(new
BorderLayout()); JScrollPane js1 = new
JScrollPane(); js1.setViewportView(t1);
getContentPane().add(js1,
java.awt.BorderLayout.CENTER);
JMenuBar mbr=new
JMenuBar(); setJMenuBar(mbr);
JMenu file=new JMenu("File");
file.setForeground(new java.awt.Color(102, 102,
255));
JMenuItem item3=new JMenuItem("New");
file.add(item3);
JMenuItem item1=new JMenuItem("Open");
JMenuItem item2=new JMenuItem("Save");
JMenuItem item13=new JMenuItem("Exit");
file.add(item1);
file.add(item2);
file.add(item13);
JMenu edit=new JMenu("Edit");
edit.setForeground(new java.awt.Color(102, 102,
255));
JMenuItem item4=new
JMenuItem("Cut"); edit.add(item4);
JMenuItem item5=new JMenuItem("Paste");
JMenuItem item6=new JMenuItem("Copy");
JMenuItem item7=new JMenuItem("Select
All"); JMenuItem item8=new
JMenuItem("Print"); edit.add(item5);
edit.add(item6);
edit.add(item7);
edit.add(item8);
JMenu format=new JMenu("Format");
format.setForeground(new java.awt.Color(102, 102,
255));
item12=new JCheckBoxMenuItem("LineWrap");
format.add(item12);
JMenu settings=new JMenu("Settings");
settings.setForeground(new java.awt.Color(102, 102,
255));
JMenuItem item9=new
JMenuItem("Font"); settings.add(item9);
mbr.add(file);
mbr.add(edit);
mbr.add(settings);
mbr.add(format);
item1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.
awt.event.KeyEvent.VK_O,java.awt.event.InputEvent.CTRL_M
ASK));
item2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.
awt.event.KeyEvent.VK_S,java.awt.event.InputEvent.CTRL_M
ASK));
item3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.
awt.event.KeyEvent.VK_N,java.awt.event.InputEvent.CTRL_M
ASK));
item4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.
awt.event.KeyEvent.VK_X,
java.awt.event.InputEvent.CTRL_MASK));
item5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.
awt.event.KeyEvent.VK_V,java.awt.event.InputEvent.CTRL_M
ASK));
item6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.
awt.event.KeyEvent.VK_C,java.awt.event.InputEvent.CTRL_M
ASK));
item7.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.
awt.event.KeyEvent.VK_A,java.awt.event.InputEvent.CTRL_M
ASK));
item8.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.
awt.event.KeyEvent.VK_P,java.awt.event.InputEvent.CTRL_M
ASK));
item9.setAccelerator(javax.swin
g.KeyStroke.getKeyStroke(java
.
awt.event.KeyEvent.VK_F,java.awt.event.InputEvent.CTRL_M
ASK));
file.setMnemonic('F');
edit.setMnemonic('E');
settings.setMnemonic('S');
format.setMnemonic('O');
item1.addActionListener(this);
item2.addActionListener(this);
item3.addActionListener(this);
item4.addActionListener(this);
item5.addActionListener(this);
item6.addActionListener(this);
item7.addActionListener(this);
item8.addActionListener(this);
item9.addActionListener(this);
item12.addActionListener(this);
item13.addActionListener(this);
addKeyListener(this);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
JOptionPane.showMessageDialog(null,"You are
Exiting");
System.exit(0);
}
});
}
public void keyPressed(KeyEvent ke){}
public void keyReleased(KeyEvent ke){}
public void keyTyped(KeyEvent ke){} public
void actionPerformed(ActionEvent ae)
String args=ae.getActionCommand();
if(args.equals("Font"))
{
font f2=new font("Font",t1);
f2.setSize(600,70);
f2.setVisible(true);
f2.setLocation(300,100);
}
if(args.equals("Cut"))
{
t1.cut();
}
if(args.equals("Paste"))
{
t1.paste();
}
if(args.equals("Copy"))
{
t1.copy();
}
if(args.equals("New"))
{
this.setTitle("Kanika's Notepad");
t1.setText("");
t1.setFont(f);
}
if(args.equals("Open"))
{
Frame f1=new Frame();
FileDialog fd=new FileDialog(f1,"Open Your
File");
fd.setSize(200,200);
fd.setVisible(true);
System.out.println(fd.getDirectory());
System.out.println(fd.getFile());
try
{
t1.setText("");
FileReader fr=newFileReader(fd.getDirectory()
+fd.getFile());
int i;
String s1="";
while((i=fr.read())!=-1)
{
s1+=((char)i);
}
t1.append(s1);
fr.close();
}
catch(Exception e){
if(args.equals("Save"))
{
Frame f1=new Frame();
FileDialog fd=new FileDialog(f1,"Save Your
File",FileDialog.SAVE);
fd.setSize(400,200);
fd.setVisible(true);
this.setTitle(fd.getFile()+"-Kanika's
Notepad");
try
{
FileWriter fw=new
FileWriter(fd.getDirectory()
+fd.getFile());
fw.write(t1.getText());
fw.close();
}
catch(Exception e)
{
}
}
if(args.equals("Select All"))
{
t1.selectAll();
}
if(args.equals("Print"))
{
ss s1 = new ss();
s1.printRecord(t1.getText());
}
if(item12.isSelected())
{
t1.setLineWrap(true);
}
else
{
t1.setLineWrap(false);
}
if(args.equals("Exit"))
{
System.exit(0);
}
}
}
Why Java?
The Java Programming Language
The Java programming language is a high-level language that
Simple
Object oriented
Robust
Secure
Architecture neutral
Portable
High performance
Multithreaded
Dynamic
Native code is code that after you compile it, the compiled
code runs on a specific hardware platform. As a platformindependent environment, the Java platform can be a bit slower
than native code. However, smart compilers, well-tuned
interpreters, and just-in-time bytecode compilers can bring
performance close to that of native code without threatening
portability. The Java compiler allows you to cascade references
to class and instance methods and variables together, resulting
in constructs like the one that appears in the sample program.
1.1 Inheritance
Generally speaking, objects are defined in terms of classes.
;
Figure-4 : Object Oriented Relationship
Each subclass
1.2 Interface
In English, an interface is a device or a system that
unrelated entities use to interact. According to this definition, a
remote control is an interface between you and a television set,
the English language is an interface between two people, and
the protocol of behaviour enforced in the military is the interface
between people of different ranks. Within the Java programming
language, an interface is a device that unrelated objects use to
interact with each other. An interface is probably most
analogous to a protocol (an agreed on behaviour). In fact, other
object-oriented languages have the functionality of interfaces,
but they call their interfaces protocols.
Capturing
similarities
among
unrelated
classes
1.3
Object
Objects are key to understanding
object-oriented
technology. You can look around you now and see many
examples of real-world objects: your dog, your desk, your
television set, your bicycle.
These real-world objects share two characteristics: They all
have state and behaviour. For example, dogs have state (name,
methods. A method is a
following
illustration
is
common
visual
brakes are on, and how steep the hill is.) These methods
are formally known as instance methods because they
inspect or change the state of a particular bicycle instance.
The object diagrams show that the object's variables make
up the center, or nucleus, of the object. Methods surround and
hide the object's nucleus from other objects in the program.
Packaging an object's variables within the protective custody of its
methods is called encapsulation this conceptual picture of an
object-a nucleus of variables packaged within a protective
membrane of methods-is an ideal representation of an object and
is the ideal that designers of object-oriented systems strive for.
However, it's not the whole story. Often, for practical reasons, an
object may wish to expose some of its variables or hide some of
its methods. In the Java programming language, an object can
specify one of four access levels for each of its variables and
methods. The access level determines which other objects and
classes can access that variable or method. Variable and method
1.4 Class
In the real world, you often have many objects of the same
kind. For example, your bicycle is just one of many bicycles in
the world. Using object-oriented terminology, we say that your
bicycle object is an instance of the class of objects known as
bicycles. Bicycles have some state (current gear, current
cadence, two wheels) and behaviour (change gears, brake) in
common. However, each bicycle's state is independent of and
can be different from that of other bicycles.
the same kind are similar and you can create a blueprint for
those objects. A software blueprint for objects is called a class.
1.4.1
1.5 Message
A single object alone is generally not very useful. Instead,
an object usually appears as a component of a larger program
or application that contains many other objects. Through the
interaction of these objects, programmers achieve higher-order
Gears)
2.
STEPS IN NOTEPAD
modules are:
CHAPTER-5
SYSTEM TESTING
SOURCE CODE
import java.awt.*;
import java.awt.event.*;
import java.io.*; import
javax.swing.*; import
java.util.*;
import java.awt.PrintJob.*;
class myfr extends JFrame implements
ActionListener,KeyListener
{
JTextArea t1;
static Font f;
JCheckBoxMenuItem item12;
//int flag=0;
String str=getTitle();
myfr(String title)
{
super(title);
t1=new JTextArea();
getContentPane().setLayout(new BorderLayout());
JScrollPane js1 = new JScrollPane();
js1.setViewportView(t1);
getContentPane().add(js1,
java.awt.BorderLayout.CENTER);
JMenuBar mbr=new JMenuBar();
setJMenuBar(mbr);
JMenu file=new JMenu("File"); file.setForeground(new
java.awt.Color(102, 102, 255));
JMenuItem item3=new
JMenuItem("New"); file.add(item3);
JMenuItem item1=new JMenuItem("Open");
JMenuItem item2=new JMenuItem("Save");
JMenuItem item13=new JMenuItem("Exit");
file.add(item1);
file.add(item2);
file.add(item13);
JMenu edit=new JMenu("Edit");
edit.setForeground(new java.awt.Color(102, 102,
255)); JMenuItem item4=new JMenuItem("Cut");
edit.add(item4);
JMenuItem item5=new JMenuItem("Paste");
JMenuItem item6=new JMenuItem("Copy");
JMenuItem item7=new JMenuItem("Select All");
JMenuItem item8=new
JMenuItem("Print"); edit.add(item5);
edit.add(item6);
edit.add(item7);
edit.add(item8);
JMenu format=new JMenu("Format");
format.setForeground(new java.awt.Color(102,
102, 255));
item12=new JCheckBoxMenuItem("LineWrap");
format.add(item12);
mbr.add(file);
mbr.add(edit);
mbr.add(settings);
mbr.add(format);
item1.setAccelerator(javax.swing.KeyStroke.getKeyStrok
e(java.awt.event.KeyEvent.VK_O,java.awt.event.InputEv
ent.CTRL_MASK));
item2.setAccelerator(javax.swing.KeyStroke.getKeyStrok
e(java.awt.event.KeyEvent.VK_S,java.awt.event.InputEve
nt.CTRL_MASK));
item3.setAccelerator(javax.swing.KeyStroke.getKeyStrok
e(java.awt.event.KeyEvent.VK_N,java.awt.event.InputEv
ent.CTRL_MASK));
item4.setAccelerator(javax.swing.KeyStroke.getKeyStrok
e(java.awt.event.KeyEvent.VK_X,
java.awt.event.InputEvent.CTRL_MASK));
item5.setAccelerator(javax.swing.KeyStroke.getKeyStrok
e(java.awt.event.KeyEvent.VK_V,java.awt.event.InputEv
ent.CTRL_MASK));
item6.setAccelerator(javax.swing.KeyStroke.getKeyStrok
e(java.awt.event.KeyEvent.VK_C,java.awt.event.InputEv
ent.CTRL_MASK));
item7.setAccelerator(javax.s
wing.KeyStroke.getKeyStrok
e(java.awt.event.KeyEvent.VK_A,java.awt.event.InputEv
ent.CTRL_MASK));
item8.setAccelerator(javax.swing.KeyStroke.getKeyStrok
e(java.awt.event.KeyEvent.VK_P,java.awt.event.InputEve
nt.CTRL_MASK));
item9.setAccelerator(javax.swing.KeyStroke.getKeyStrok
e(java.awt.event.KeyEvent.VK_F,java.awt.event.InputEve
nt.CTRL_MASK));
file.setMnemonic('F');
edit.setMnemonic('E');
settings.setMnemonic('S');
format.setMnemonic('O');
item1.addActionListener(this);
item2.addActionListener(this);
item3.addActionListener(this);
item4.addActionListener(this);
item5.addActionListener(this);
item6.addActionListener(this);
item7.addActionListener(this);
item8.addActionListener(this);
item9.addActionListener(this);
item12.addActionListener(this);
item13.addActionListener(this);
addKeyListener(this);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
JOptionPane.showMessageDialog(null,"You
are Exiting");
System.exit(0);
/* int i;
String s1 = "Do you Want to Exit";
i= JOptionPane.showConfirmDialog(null,s1,"Exit
Message", JOptionPane.YES_NO_OPTION); if(i!=1)
MessagePane.setMessagePaneProvider("Want to Save");
MessagePane pane =
MessagePane.getDocumentInstance(myfr);
Result result = pane.show(myMessage);
if (result.userChose(Option.SAVE))
{
// save our document...
}
else if (result.userChose(Option.CANCEL))
{
// cancel...
}
*/
}
});
}
public void keyReleased(KeyEvent ke)
{
}
public void keyTyped(KeyEvent ke)
{
}
public void actionPerformed(ActionEvent ae)
{
String args=ae.getActionCommand();
if(args.equals("Font"))
{
font f2=new font("Font",t1);
f2.setSize(600,70);
f2.setVisible(true);
f2.setLocation(300,100);
}
if(args.equals("Cut"))
{
t1.cut();
}
if(args.equals("Paste"))
{
t1.paste();
}
if(args.equals("Copy"))
{
t1.copy();
}
if(args.equals("New"))
{
this.setTitle("TextEditor Plus");
t1.setText("");
t1.setFont(f);
}
if(args.equals("Open"))
{
{
t1.setText("");
FileReader fr=new
FileReader(fd.getDirectory() +fd.getFile());
int i;
String s1="";
while((i=fr.read())!=-1)
{
s1+=((char)i);
}
t1.append(s1);
fr.close();
}
catch(Exception e)
{
}
}
if(args.equals("Save"))
{
String str1,str2;
1/
2/
1/
File",FileDialog.SAVE);
fd.setSize(400,200);
fd.setVisible(true);
str1=fd.getDirectory();
1/
str2=fd.getFile();
1/
//System.out.println(fd.getDirectory());
//System.out.println(fd.getFile());
this.setTitle(fd.getFile()+"-TextEditor Plus");
1/
flag=1;
try
{
FileWriter fw=new FileWriter(fd.getDirectory()
+fd.getFile());
fw.write(t1.getText());
fw.close();
}
catch(Exception e)
{
}
}
//if(flag==1)
//{
Frame
1/
f1=new
Frame(); //try{
2/ FileWriter
FileWriter(str1+str2);
//fw.write(t1.getText());
1/
fw.close();
//}
//catch(Exception e)
fw=new
//{}
//}
//}
if(args.equals("Select All"))
{
t1.selectAll();
}
if(args.equals("Print"))
{
ss s1 = new ss();
s1.printRecord(t1.getText());
}
if(item12.isS
elected())
{
t1.setLineWrap(true);
}
else
{
t1.setLineWrap(false);
}
if(args.equals("Exit"))
{
System.exit(0);
}
}
}
class mynotepad
{
public static void main(String s[])
{
myfr f=new myfr("TextEditor
Plus"); f.setSize(400,400);
f.setVisible(true);
f.setLocation(0,0);
}
}
class font extends Frame implements ActionListener
Choice c1,c2,c3;
Button b1,b2;
JTextArea t1;
font(String s,JTextArea jt)
{
super(s);
t1=jt;
c1=new Choice();
c1.add("Arial");
c1.add("Adobe Caslon
Pro"); c1.add("Arial Black");
c1.add("Arial Narrow");
c1.add("Arial Rounded MT
Bold"); c1.add("Arial Unicode
MS"); c1.add("Arno Pro");
c1.add("Arno Pro Caption");
c1.add("Arno Pro Display");
c1.add("Baskerville Old
Face"); c1.add("Batang");
c1.add("Bauhaus 93");
c1.add("Bell Gothic Std
Black"); c1.add("Comic Sans
MS"); c1.add("Consolas");
c1.add("Cooper Std Black");
c1.add("Corbel");
c1.add("DFKai-SB");
c1.add("DilleniaUPC");
c1.add("Forte");
setLayout(new
FlowLayout()); add(new
Label("Font")); add(c1);
c2=new Choice();
c2.add("10");
c2.add("12");
c2.add("14");
c2.add("16");
c2.add("18");
c2.add("20");
c2.add("22");
c2.add("24");
c2.add("28");
c2.add("32");
c2.add("36");
c2.add("40");
c2.add("44");
c2.add("48");
c2.add("60");
c2.add("72");
add(new Label("Size"));
add(c2);
c3=new Choice();
c3.add("Bold");
c3.add("Italic");
c3.add("Plain");
add(new Label("Font
Style")); add(c3);
b1=new Button("Ok");
b2=new Button("Cancel");
b1.addActionListener(this);
b2.addActionListener(this);
add(b1);
add(b2);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
setVisible(false);
}
});
}
{
Font f=null;
if(c3.getSelectedItem()=="Bold")
f=new
Font(""+c1.getSelectedItem(),Font.BOLD,Integer.parseInt
(c2.getSelectedItem()));
}
if(c3.getSelectedItem()=="Plain")
{
f=new
Font(""+c1.getSelectedItem(),Font.PLAIN,Integer.parseIn
t(c2.getSelectedItem()));
}
if(c3.getSelectedItem()=="Italic")
{
f=new
Font(""+c1.getSelectedItem(),Font.ITALIC,Integer.parseI
nt(c2.getSelectedItem()));
}
if(ae.getSource()==b1)
{
t1.setFont(f);
setVisible(false);
}
if(ae.getSource()==b2)
{
setVisible(false);
}
}
12);
Properties p = new Properties();
PrintJob pjob = getToolkit().getPrintJob(this,
"Print report", p);
if (pjob != null)
{
Graphics pg =
pjob.getGraphics(); if (pg != null)
{
FontMetrics fm =
pg.getFontMetrics(typeface); int margin = 20;
int pageHeight =
pjob.getPageDimension().height - margin;
int fontHeight = fm.getHeight(); int
fontDescent = fm.getDescent();
int curHeight = margin;
String nextLine;
pg.setFont (typeface);
try
{
do
{
nextLine = lnr.readLine();
if (nextLine != null)
{
if ((curHeight + fontHeight) >
pageHeight) { // New Page
pg.dispose();
pg = pjob.getGraphics();
curHeight = margin;
curHeight += fontHeight;
if (pg != null)
{
pg.setFont (typeface);
pg.drawString (nextLine, margin,
curHeight - fontDescent);
}
}
}
while (nextLine != null);
}
catch (EOFException eof)
{
}
catch (Throwable t)
{
t.printStackTrace();
}
}
pg.dispose();
}
if (pjob != null)
pjob.end();
CONCLUSION
REFRENCES
[1]