note pad
TRANSCRIPT
CERTIFICATE
This is to certify that ROHIT AGGARWAL the student of B.TECH(COMPUTER SCIENCE) IV semester at Shree Ram Mulkh Instt. of Engg. & Tech.,Ambala has undergone training in Java languge for a period of six weeks on the project entitled “Notepad”. He has completed his training and project successfully in time.
During the period of training his conduct was very good. He was sincere and always ready to learn things and use them practically.
I wish him all the success in the future.
SUPERVISIOR(Poonam Sehrawat)NIITNajafgarh
ACKNOWLEDGEMENTS
It is my privilege to express my profound sense of gratitude to my supervisor Ms.
Poonam Sehrawat for their invaluable guidance, positive attitude and constant
encouragement throughout my project work. It has been wonderful to work under
her supervision, which gave me motivation and experience.
I am grateful to Ms. Poonam Sehrawat Head of Department of Java, NIIT, New
Delhi and other faculty members of the department for their providing us
necessary facilities I needed at various stages of this work.
I am thankful to all my colleagues and friends.
Finally, I would like to express my gratitude to my family members for their moral
support and encouragement.
(Rohit Aggarwal)
PREFACE
This six weeks training is the part of four year degree course. It was really a great
experience to work in computer lab of NIIT , one gets an opportunity to see from
close quarters about the environment in which an engineer works.
We joined the computer lab of NIIT under the guidance of skilled and experienced
teachers in JAVA, we had learned a lot during the training and really enjoyed my
work at the laboratory.
Table of contents
S.No. Contents
1. NIIT
2. Abstract
3. Objective of the Project
4. Requirement Analysis
4.1 Need and Justification
4.2 Feasibility Study
4.3 Use Case Diagram
4.4 Flow Chart
4.5 System Requirement specification
5. System Design
6. Coding and snapshots
7. Software testing
8. Further Enhancement
9. References
NIIT
NIIT is a leading Global Talent
Development Corporation, building a
skilled manpower pool for global industry
requirements. The company which was set
up in 1981, to help the nascent IT industry
overcome its human resource challenges,
has today grown to rank among the
world’s leading talent development
organisations offering learning solutions
to Individuals, Enterprises and Institutions
across 40 countries.
NIIT’s training solutions in IT, Business
Process Outsourcing, Banking, Finance
and Insurance, Executive Management
Education, and Communication and
Professional Life Skills, touch five million
learners every year. NIIT’s expertise in
learning content development, training
delivery and education process
management make us the most preferred
training partner, worldwide.
Research-based Innovation, a key driver at NIIT, has enabled us to develop
programmes and curricula that use cutting-edge instructional design
methodologies and training delivery. NIIT’s Individual Learning Solutions include
industry-endorsed IT training programmes like GNIIT, Integrated programmes for
Engineers (NIIT Edgeineers) and Infrastructure Management programmes (NIIT
GlobalNet+).
NIIT Imperia, Centre for Advanced Learning, brings Executive Management
Education Programmes from premier B-schools in India, to the doorsteps of
working professionals.
NIIT Institute of Finance Banking & Insurance (IFBI), set up by NIIT with equity
participation from ICICI Bank, offers programmes for individuals and corporates
in the Banking, Financial Services and Insurance segments.
NIIT Institute of Finance Banking & Insurance (IFBI), set up by NIIT with equity
participation from ICICI Bank, offers programmes for individuals and corporates
in the Banking, Financial Services and Insurance segments.
NIIT Uniqua, Centre for Process Excellence, addresses the increasing demand for
skilled workers in the business and technology services industry by providing
training programmes in relevant areas. This initiative is a part of the NIIT Institute
of Process Excellence, a NIIT-Genpact joint venture.
NIIT’s School Learning Solutions offer turnkey IT integration programmes for
schools and has provided computer-based learning to nearly 7.8 million students
in over 9,500 Government and private schools. NIIT eGuru, a comprehensive
range of learning solutions for schools is powering NIIT’s portfolio for the K-12
segment.
In order to address the vast population of underprivileged, school-aged children,
NIIT launched the Hole-in-the-Wall education initiative, which has been
recognised and acclaimed globally. Our achievements in the area of Minimally
Invasive Education earned us the coveted Digital Opportunity Award,
conferred by the World Information Technology Services Alliance (WITSA)
in 2008.
NIIT’s Corporate Learning Solutions business offers integrated learning solutions,
including strategic consulting, learning design, content development, delivery,
technology, assessment and learning management to Fortune 500 companies,
Universities, Technology companies, Training corporations and Publishing
houses. Element K, the spearhead of our corporate learning solutions, provides a
tailored combination of catalogue learning products, technology, and services to
customers and partners. The offerings include: vLab®: hands-on labs, instructor-
led courseware, comprehensive e-reference libraries, technical journals, and
KnowledgeHub™ , a hosted learning management platform. NIIT, together with
Element K, is now the first and the best choice for comprehensive learning
solutions, worldwide.
Abstract
Notepad is a basic text editor that can be used to create simple documents. The
most common use for Notepad is to view or edit text (.txt) files, but many users
find Notepad a simple tool for creating Web pages. It has been a quest for many
programmers to build Notepad using different programming languages. I have
built up a basic Notepad program using Java technology. This Notepad supports
basic text editing features such as cut, copy, paste, delete etc.
Objectives of the Project
The basic objective of this project is to provide its users an easy to use Notepad
application.
The Objectives can be categorized as:
Easily accessible Notepad application.
Allow easy file maintenance.
Allow easy document editing.
Requirement Analysis
Requirements analysis in systems engineering and software engineering,
encompasses those tasks that go into determining the needs or conditions to meets
for a new or altered product, taking account of the possibly conflicting
requirements of the various stakeholders, such as beneficiaries or users.
Requirements analysis is critical to the success of a development project.
Requirements must be actionable, measurable, testable, related to identified
business needs or opportunities, and defined to a level of detail sufficient for
system design.
Requirements for this application are gathered from the various sites so as to have
the idea about the type and working. Books on different websites are referred.
Need and justification
Notepad is easy to use, volatile application which can be used for preparing files
of various formats, like web pages, programs of many languages etc.
Keeping in mind the popularity of the use of Notepad for preparing almost all
types of files, its need is justified.
Feasibility Study
o Technical Feasibility
The proposed application is technically feasible because the
hardware and software required to develop and implement this
application can be made available easily. It uses easy to navigate
user interface thus, this will reduce the length of the process required
to complete a request.
o Economical Feasibility
According to the economic point of view the system seems feasible
because after the one time cost of the hardware and the development
of the software, the running cost is minimal. The user just needs to
use the application as and when required.
o Operational Feasibility
The proposed application is very simple to operate. This is because
of the reason that a Notepad is very easy to learn and use, no special
training is needed to use it.
o Time and Resources
The time required to use the application is very less. And the various
resources required to develop the application were easily available.
Use Case Diagram
A use case is a methodology used in system analysis to identify, clarify, and organize system requirements. The use case is made up of a set of possible sequences of interactions between systems and users in a particular environment and related to a particular goal. It consists of a group of elements (for example, classes and interfaces) that can be used together in a way that will have an effect larger than the sum of the separate elements combined. The use case should contain all system activities that have significance to the users. A use case can be thought of as a collection of possible scenarios related to a particular goal, indeed, the use case and goal are sometimes considered to be synonymous.
A use case (or set of use cases) has these characteristics:
Organizes functional requirements Models the goals of system/actor (user) interactions Records paths (called scenarios) from trigger events to goals Describes one main flow of events (also called a basic course of action),
and possibly other ones, called exceptional flows of events (also called alternate courses of action)
Is multi-level, so that one use case can use the functionality of another one.
Use cases can be employed during several stages of software development, such as planning system requirements, validating design, testing software, and creating an outline for online help and user manuals.
File related tasks
Editing the document
FormattingUser Application
Help
<<include>>
Open, Close, Save
Copy, Cut, Paste, Delete
Font, Word Wrap
<<include>>
<<include>>
USE CASE FOR THE APPLICATION:
Flowchart
A flowchart is a common type of chart, that represents an algorithm or process, showing the steps as boxes of various kinds, and their order by connecting these with arrows. Flowcharts are used in analyzing, designing, documenting or managing a process or program in various fields.
Flow chart building blocks:
Symbols
A typical flowchart from older Computer Science textbooks may have the following kinds of symbols:
Start and end symbols Represented as lozenges, ovals or rounded rectangles, usually containing the word "Start" or "End", or another phrase signaling the start or end of a process, such as "submit enquiry" or "receive product".
Arrows Showing what's called "flow of control" in computer science. An arrow coming from one symbol and ending at another symbol represents that control passes to the symbol the arrow points to.
Processing steps Represented as rectangles. Examples: "Add 1 to X"; "replace identified part"; "save changes" or similar.
Input/Output Represented as a parallelogram. Examples: Get X from the user; display X.
Conditional or decision Represented as a diamond (rhombus). These typically contain a Yes/No question or True/False test. This symbol is unique in that it has two arrows coming out of it, usually from the bottom point and right point, one corresponding to Yes or True, and one corresponding to No or False. The arrows should always be labeled. More than two arrows can be used, but this is normally a clear indicator that a complex decision is being taken, in
which case it may need to be broken-down further, or replaced with the "pre-defined process" symbol.
A number of other symbols that have less universal currency, such as:
A Document represented as a rectangle with a wavy base; A Manual input represented by parallelogram, with the top irregularly
sloping up from left to right. An example would be to signify data-entry from a form;
A Manual operation represented by a trapezoid with the longest parallel side at the top, to represent an operation or adjustment to process that can only be made manually.
A Data File represented by a cylinder
Flowcharts may contain other symbols, such as connectors, usually represented as circles, to represent converging paths in the flow chart. Circles will have more than one arrow coming into them but only one going out. Some flow charts may just have an arrow point to another arrow instead. These are useful to represent an iterative process (what in Computer Science is called a loop). A loop may, for example, consist of a connector where control first enters, processing steps, a conditional with one arrow exiting the loop, and one going back to the connector. Off-page connectors are often used to signify a connection to a (part of another) process held on another sheet or screen. It is important to remember to keep these connections logical in order. All processes should flow from top to bottom and left to right.
APPLICATION FLOWCHART
START
READ LINK
Is Link= File
YES
NO
Is Link= Edit
YES
NO
Is Link= Format
YES
NO
Display formatting options
Display editing options
YES
NO
Is Link= Help
Display help
Display file handling options
Perform selected operation
End
System Requirement Specifications
The system requirements include
(a) Functional requirements (i.e. requirements related to functions to
be done)
(b) System requirements (i.e. requirements for hardware including
specification of any specialized tool to be used on the project,
firmware, software & user interfaces.
(a) Functional Requirements:
(i) Receives (Inputs): The system receives the command for the
tasks to be done, from menu items as an input.
(ii) Process: the system processes the input and performs the
required function on the basis of that.
(iii) Generates (Outputs): the system will perform the required task.
(b) System requirements :
The software required for the project is JVM (Java Virtual Machine).
The hardware specifications for the system are:
Pentium (133 MHz) with 16MB RAM
Color/Mono monitor.
104 key keyboard.
The hardware specification may be higher than this.
SYSTEM’S STUDY
General Description:
This application interacts with the user by the help of a graphical user interface
provided. The documentation is done using file handling utility provided in Java.
Environment description:
This application needs Java Virtual Machine (JVM) to run.
Inputs:
Input from the operator can be any of the commands related to file handling or
editing files.
Outputs:
Depending upon the operator command, the respective sub procedures are
triggered and further processing takes place. The result of the command shall be
displayed on the front end, which is the provided user interface in this case.
Functional division:
The most important part of the system is the designing part. The main parts of
designing are: Input design, Output design and File design.
Input design:
Every system depends upon some input for processing, and the accuracy of input
is the key to input designing.
Output design:
Every system generates output after processing the received inputs. The main
purpose of this application is to provide its users an easy to use text editor.
File design:
The most challenging phase in this system is designing the program files.
The kind of file used is:
Program files
Functionally, the application will be classified as a GUI interface that interacts
with the operator and further with a file handling system.
Functional Requirements:
GUI:
Graphical user interface has to be built so as to ease the operator. It shall take in
commands based on menu selections and send commands to the back end process.
The results are again displayed on the GUI.
Types of operators:
The operator/user for the application can be anyone who wishes to have a basic
and easy to use text editor.
Facilities available:
File handling
Edit options to make changes in the existing files
Formatting option
Help menu
System Design
Proposed System interface description:
Three project major components to the
1. A front end
Depending on the type of interface (Graphical), the front end handles the
display accordingly. This part will run on PC and provide the input output
capabilities.
2. A back end
Irrespective of the type of front end, backend provides a base to the
commands executed at front end.
3. Connection between front end and backend
The connectivity between the two is established by
Constraints:
The design should support graphical interface functions.
It should involve minimal hardware support and should be cost effective.
It should be able to support new modifications with minimal changes.
Code
The given application consists of the following two files: Notepad file (Notepad.java) FontChooser file (JFontChooser.java)
The code for both the files is given below:
Notepad.Java
import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.Date;import java.util.Calendar;import java.util.GregorianCalendar;import javax.swing.JOptionPane;import javax.swing.text.*;import java.awt.datatransfer.*;import javax.swing.JDialog;
public class Notepad extends JFrame implements ActionListener{private JFrame f;private JPanel p;private JMenuBar mb;private JMenu mFile,mEdit,mFormat,mHelp;private JTextArea t;private JMenuItem fNew,fOpen,fSave,fExit;private JMenuItem eCut,eCopy,ePaste,eDelete,eTime,eSelectAll;private JMenuItem fFont;private JCheckBoxMenuItem fWrap;private JMenuItem hNotepad;
private JScrollPane sc;private String str;
public Notepad(){f=new JFrame("Notepad");p=new JPanel();
//INITIALIZING MENUS
mb=new JMenuBar();mFile=new JMenu("File");mEdit=new JMenu("Edit");mFormat=new JMenu("Format");mHelp=new JMenu("Help");
//INITIALIZING FILE MENU ITEMS
fNew=new JMenuItem("New");fOpen=new JMenuItem("Open");fSave=new JMenuItem("Save");fExit=new JMenuItem("Exit");
//INITIALIZING EDIT MENU ITEMS
eCut=new JMenuItem("Cut");eCopy=new JMenuItem("Copy");ePaste=new JMenuItem("Paste");eDelete=new JMenuItem("Delete");eTime=new JMenuItem("Date & Time");eSelectAll=new JMenuItem("Select All");
//INITIALIZING FORMAT MENU ITEMS
fWrap=new JCheckBoxMenuItem("Word Wrap");fFont=new JMenuItem("Font");
//INITIALIZING HELP MENU ITEMS
hNotepad=new JMenuItem("About Notepad");
//ADDING MENU ITEMS TO MENUS//ADDING FILE MENU ITEMS
mFile.add(fNew);mFile.add(fOpen);mFile.add(fSave);mFile.addSeparator();mFile.add(fExit);
//ADDING EDIT MENU ITEMS
mEdit.add(eCut);mEdit.add(eCopy);mEdit.add(ePaste);mEdit.add(eDelete);mEdit.add(eTime);mEdit.add(eSelectAll);
//ADDING FORMAT MENU ITEMS
mFormat.add(fWrap);mFormat.add(fFont);
//ADDING HELP MENU ITEMS
mHelp.add(hNotepad);
//ADDING EVENT HANDLERS TO FILE MENU ITEMS
fNew.addActionListener(this);fOpen.addActionListener(this);fSave.addActionListener(this);fExit.addActionListener(this);
//ADDING EVENT HANDLERS TO EDIT MENU ITEMS
eCut.addActionListener(this);eCopy.addActionListener(this);ePaste.addActionListener(this);eDelete.addActionListener(this);eTime.addActionListener(this);eSelectAll.addActionListener(this);
//ADDING EVENT HANDLERS TO FORMAT MENU ITEMS
fWrap.addActionListener(this);fFont.addActionListener(this);
//ADDING EVENT HANDLERS TO HELP MENU ITEMS
hNotepad.addActionListener(this);
//ADDING MENUS TO MENUBAR
mb.add(mFile);mb.add(mEdit);mb.add(mFormat);mb.add(mHelp);
//ADDING MENUBAR TO THE FORM
f.setJMenuBar(mb);
t=new JTextArea(10,10);sc=new JScrollPane(t);
//To set ScrollBars
sc.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);sc.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);p.add(sc);
f.getContentPane().add(p);
f.setSize(100,100);f.pack();f.setVisible(true);f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}
//MAIN METHOD
public static void main(String[] args){Notepad n=new Notepad();}
//PERFORMING EVENT HANDLING
public void actionPerformed(ActionEvent e){
//To find the source of the event.
if(e.getSource()==fNew){t.setText("");}
else if(e.getSource()==fExit){f.dispose();}
else if(e.getSource()==fOpen){//For dialog box use JFileChooser
JFileChooser open=new JFileChooser();int option=open.showOpenDialog(this);if(option==JFileChooser.APPROVE_OPTION){
this.t.setText("");try{BufferedReader b=new BufferedReader(new
FileReader(open.getSelectedFile().getPath()));String s=b.readLine();while(s!=null){this.t.append(s+"\n");s=b.readLine();}b.close();}catch(Exception e1){System.out.println(e1.toString());}}}
else if(e.getSource()==fSave){JFileChooser save=new JFileChooser();int option=save.showSaveDialog(this);try{if(option==JFileChooser.APPROVE_OPTION){File file=save.getSelectedFile();if(file.exists()){int response=JOptionPane.showConfirmDialog(null,"File already exists. Do you want to continue?","Overwrite Confirmation",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);if(response==JOptionPane.CANCEL_OPTION){}else{BufferedWriter b=new BufferedWriter(new FileWriter(save.getSelectedFile().getPath()));
b.write(this.t.getText());b.close();}}else{
BufferedWriter b=new BufferedWriter(new FileWriter(save.getSelectedFile().getPath()));
b.write(this.t.getText());b.close();}}}catch(Exception e1){System.out.println(e1.toString());}}
else if(e.getSource()==eTime){Date date=new Date();GregorianCalendar calendar=new GregorianCalendar();calendar.setTime(date);
String
strTime=calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
String
strDate=calendar.get((Calendar.MONTH)+1)+"/"+calendar.get(Calendar.DATE)+"/"+calendar.get(Calendar.YEAR);
String time=strTime+" "+strDate;
int start=this.t.getSelectionStart();int end=this.t.getSelectionEnd();this.t.replaceRange(time,start,end);
}
else if(e.getSource()==eCopy){str=this.t.getSelectedText();}
else if(e.getSource()==eCut){str=this.t.getSelectedText();int start=this.t.getSelectionStart();int end=this.t.getSelectionEnd();this.t.replaceRange("",start,end);StringSelection ss = newStringSelection(str);}
else if(e.getSource()==ePaste){int start=this.t.getSelectionStart();int end=this.t.getSelectionEnd();this.t.replaceRange(str,start,end);}
else if(e.getSource()==eDelete){int start=this.t.getSelectionStart();int end=this.t.getSelectionEnd();this.t.replaceRange("",start,end);}
else if(e.getSource()==eSelectAll){this.t.selectAll();}
else if(e.getSource()==fFont){JFontChooser fd = new JFontChooser(this,t.getFont());fd.show();if(fd.getReturnStatus() == fd.RET_OK){ t.setFont(fd.getFont());
}fd.dispose();}
else if(e.getSource()==fWrap){t.setLineWrap(true);sc.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);}
else if(e.getSource()==hNotepad){JOptionPane.showMessageDialog(this,"Created by ROHIT AGGARWAL","Notepad",JOptionPane.INFORMATION_MESSAGE);}
}}
JFontChooser.java
Import java.awt.*;public class JFontChooser extends javax.swing.JDialog { public static final int RET_CANCEL = 0; public static final int RET_OK = 1; private Font font; public JFontChooser(java.awt.Frame parent, Font font) { super(parent); this.font = font; initComponents(); lblPreview.setFont(font); } public JFontChooser(java.awt.Frame parent) { super(parent); this.font = new Font("Dialog",Font.PLAIN,12); initComponents(); lblPreview.setFont(font); } public JFontChooser(Font font) { super((javax.swing.JFrame)null); this.font = font; initComponents(); lblPreview.setFont(font); } public JFontChooser() { super((javax.swing.JFrame)null); this.font = new Font("Dialog",Font.PLAIN,12); initComponents(); lblPreview.setFont(font); } public Font getFont(){ return font; }
public int getReturnStatus() { return returnStatus; } private void initComponents() { java.awt.GridBagConstraints gridBagConstraints;
mainPanel = new javax.swing.JPanel(); fontPanel = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); lstFont = new javax.swing.JList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); jScrollPane2 = new javax.swing.JScrollPane(); lstStyle = new javax.swing.JList(); jScrollPane3 = new javax.swing.JScrollPane(); lstSize = new javax.swing.JList(); previewPanel = new javax.swing.JPanel(); lblPreview = new javax.swing.JLabel(); buttonPanel = new javax.swing.JPanel(); okButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton();
setTitle("Select Font"); setModal(true); setResizable(false); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { closeDialog(evt); } });
mainPanel.setLayout(new java.awt.GridLayout(2, 1));
fontPanel.setLayout(new java.awt.GridBagLayout());
jLabel1.setText("Font");
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1); gridBagConstraints.weightx = 2.0; fontPanel.add(jLabel1, gridBagConstraints);
jLabel2.setText("Style"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1); fontPanel.add(jLabel2, gridBagConstraints);
jLabel3.setText("Size"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1); gridBagConstraints.weightx = 0.2; fontPanel.add(jLabel3, gridBagConstraints);
lstFont.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); lstFont.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { lstFontValueChanged(evt); } });
jScrollPane1.setViewportView(lstFont);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 1; gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1); gridBagConstraints.weightx = 2.0; fontPanel.add(jScrollPane1, gridBagConstraints);
lstStyle.setModel(new javax.swing.AbstractListModel() { String[] strings = { "Plain", "Bold", "Italic", "Bold Italic" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; }
}); lstStyle.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); lstStyle.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { lstStyleValueChanged(evt); } });
jScrollPane2.setViewportView(lstStyle);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 1; gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1); fontPanel.add(jScrollPane2, gridBagConstraints);
lstSize.setModel(new javax.swing.AbstractListModel() { String[] strings = { "8", "10", "11", "12", "14", "16", "20", "24", "28", "36", "48", "72", "96" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); lstSize.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); lstSize.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { lstSizeValueChanged(evt); } });
jScrollPane3.setViewportView(lstSize);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 1; gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
gridBagConstraints.weightx = 0.2; fontPanel.add(jScrollPane3, gridBagConstraints);
mainPanel.add(fontPanel);
previewPanel.setLayout(new java.awt.BorderLayout());
previewPanel.setBorder(new javax.swing.border.TitledBorder(null, "Preview", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 0, 12))); lblPreview.setFont(new java.awt.Font("Dialog", 0, 12)); lblPreview.setText("ABCDEFG abcdefg"); previewPanel.add(lblPreview, java.awt.BorderLayout.CENTER);
mainPanel.add(previewPanel);
getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER);
buttonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
okButton.setText("OK"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } });
buttonPanel.add(okButton);
cancelButton.setText("Cancel"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } });
buttonPanel.add(cancelButton);
getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH);
pack();
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setSize(new java.awt.Dimension(443, 429)); setLocation((screenSize.width-443)/2,(screenSize.height-429)/2); }
private void lstStyleValueChanged(javax.swing.event.ListSelectionEvent evt) { int style = -1; String selStyle = (String)lstStyle.getSelectedValue(); if(selStyle=="Plain") style = Font.PLAIN; if(selStyle=="Bold") style = Font.BOLD; if(selStyle=="Italic") style = Font.ITALIC; if(selStyle=="Bold Italic") style = Font.BOLD + Font.ITALIC; font = new Font(font.getFamily(),style,font.getSize()); lblPreview.setFont(font); } private void lstSizeValueChanged(javax.swing.event.ListSelectionEvent evt) { int size = Integer.parseInt((String)lstSize.getSelectedValue()); font = new Font(font.getFamily(),font.getStyle(),size); lblPreview.setFont(font); }
private void lstFontValueChanged(javax.swing.event.ListSelectionEvent evt) { font = new Font((String)lstFont.getSelectedValue(),font.getStyle(),font.getSize()); lblPreview.setFont(font); } private void okButtonActionPerformed(java.awt.event.ActionEvent evt) { doClose(RET_OK); } private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { doClose(RET_CANCEL); } private void closeDialog(java.awt.event.WindowEvent evt) {
doClose(RET_CANCEL); } private void doClose(int retStatus) { returnStatus = retStatus; setVisible(false); } public static void main(String args[]) { new JFontChooser().show(); } private javax.swing.JPanel fontPanel; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel2; private javax.swing.JList lstSize; private javax.swing.JButton okButton; private javax.swing.JList lstFont; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JList lstStyle; private javax.swing.JPanel mainPanel; private javax.swing.JButton cancelButton; private javax.swing.JPanel previewPanel; private javax.swing.JLabel lblPreview; private javax.swing.JPanel buttonPanel; private javax.swing.JScrollPane jScrollPane3; private int returnStatus = RET_CANCEL;}
SNAPSHOTS
The following figures show some of the snapshots of the application Start page of application
When user wishes to open a previously existing file, an open file dialog box is shown, as is shown in the following snapshot
When user needs to save his/her file, the user is shown a save file dialog box to achieve this, as shown below
The application also provides provision for document editing tasks, the possible options are shown in the following snapshot
The formatting option is also there
If user wishes to set the font of the text to be typed in the document, he/she can use the font menu item from format menu as shown in following snapshot
The help menu is used to show the information about the application as follows
As can be seen from the snapshots, this application provides its users an easy to use text editor, where the user can either open or save files and also can use editing options.
Software Testing
The software engineering process may be viewed as the spiral illustrated in Figure. Initially, system engineering defines the role of software and leads to software requirements analysis, where the information domain, function, behavior, performance, constraints, and validation criteria for software are established. Moving inward along the spiral, we come to design and finally to coding. To develop computer software, we spiral inward along streamlines that decrease the level of abstraction on each turn.
Software testing steps
Unit Testing
The module interface is tested to ensure that information properly flows into and out of the program unit under test.
Unit Test
Integration Testing
Integration testing is a systematic technique for constructing the program structure while at the same time conducting tests to uncover errors associated with interfacing. The objective is to take unit tested components and build a program structure that has been dictated by design.
Top-down Integration:
Top-down integration testing is an incremental approach to construction of program structure. Modules are integrated by moving downward through the control hierarchy, beginning with the main control module (main program). Modules subordinate (and ultimately subordinate) to the main control module are incorporated into the structure in either a depth-first or breadth-first manner.
Then, the central and right hand control paths are built. Breadth-first integration incorporates all components directly subordinate at each level, moving across the structure horizontally. From the figure, components M2, M3, and M4 (a replacement for stub S4) would be integrated first. The next control level, M5, M6, and so on, follows.
Validation Testing
At the culmination of integration testing, software is completely assembled as a package, interfacing errors have been uncovered and corrected, and a final series of software tests—validation testing—may begin.
System Testing
Testing is the last phase before the final softwareis delivered. So we need to have a perfect testing plan which can detect any type of error that may exist in the software.
Though we put our effort in detecting errors soon after they are produced by verifying them on each phases of development, however, most of these verification activities has been made in early phases of software development which is mostly based on human evaluation so it cannot guarantee that the system software do not have any errors.
Finally to rectify these errors we have made a test plan which works as follows:
Test PlanIn our test plan we divided testing on different level so that testing can be
performed from basic unit testing to final acceptance testing.
Unit Testing
1. Test Units We first try to find out or fix the units to be tested and we found that two or
more modules can be taken together and can be dealt as a single unit. For this we keep our project in mind so that testing should be performed in accordance with the requirements of the projects. As our project using developer as front-end tool we made every form and each report (among various types of reports) as basic units. For each unit, test cases have been made and their output verified. Then we came to integration of modules for integration testing.
2. Features TestedAll the functional features specified in the requirements have been tested.
3. Approach for testingWe adopted both the methods means white box testing as well as Black box
testing.In Unit Testing our main emphasis was to look for branching. If branching
is correct it will ensure that flow of control will be perfect. After branch testing, we tested units on functional level.
System testing was largely functional testing in which we had put data and checked for desired output.
4. Acceptance Testing With ModulesAnd the last phase of testing was acceptance testing in which we had put
real time data which has been collected during analysis, and tested for their performance as well as correctness.
This way, we have done rigorous testing of software which ensures that the software will be robust and reliable.
Further Enhancement
This Notepad application provides various functionalities like saving a file,
opening an existing file, and also some of the editing options.
Further enhancement of the application can contain options like file printing
option, page setup option, file compression and expansion options, which are not
included in this version of the application.
References
1. NIIT courseware
2. Head First Java, Second Edition by Kathy Sierra & Bert Bates
3. The Complete Reference, Second Edition by Thomas Powell & Fritz Schneider
4. http://www.w3schools.com