SlideShare a Scribd company logo
package test; 
import java.awt.*; 
import java.awt.event.*; 
import java.awt.datatransfer.*; 
import java.io.*; 
import javax.swing.*; 
import javax.swing.text.*; 
public class notepad extends JPanel 
{ 
JTextArea jta = new JTextArea("", 24, 40); 
JScrollPane jsp = new JScrollPane(jta); 
JMenuBar jmb = new JMenuBar(); 
JMenu file = new JMenu("File"); 
JMenu edit = new JMenu("Edit"); 
JMenu search = new JMenu("Search"); 
JMenu help = new JMenu("Help"); 
JMenuItem jmi; 
JToolBar toolBar=new JToolBar(); 
Clipboard clipbd = getToolkit().getSystemClipboard(); 
class newL implements ActionListener 
{ 
public void actionPerformed(ActionEvent e) 
{ 
jta.setDocument(new PlainDocument()); 
} 
} 
class openL implements ActionListener 
{ 
public void actionPerformed(ActionEvent e) 
{ 
JFileChooser fc = new JFileChooser(); 
int returnVal = fc.showDialog(notepad.this, "Open file"); 
if(returnVal == JFileChooser.APPROVE_OPTION) 
{ 
String file = fc.getSelectedFile().getPath(); 
if(file == null) 
{ 
return; 
} 
try 
{ 
Reader in = new FileReader(file); 
char[] buff = new char[4096]; 
int nch; 
while((nch = in.read(buff, 0, buff.length)) != -1) 
{ 
jta.setDocument(new PlainDocument()); 
jta.append(new String(buff, 0, nch)); 
} 
} 
catch (IOException io) 
{ 
System.err.println("IOException: " + io.getMessage()); 
} 
} 
else 
{ 
return;
} 
} 
} 
class saveL implements ActionListener 
{ 
public void actionPerformed(ActionEvent e) 
{ 
JFileChooser fc = new JFileChooser(); 
int returnVal = fc.showSaveDialog(notepad.this); 
if(returnVal == JFileChooser.APPROVE_OPTION) 
{ 
String savefile = 
fc.getSelectedFile().getPath(); 
if(savefile == null) 
{ 
return; 
} 
else 
{ 
String docToSave = jta.getText(); 
if(docToSave != null) 
{ 
FileOutputStream fstrm = 
null; 
BufferedOutputStream 
ostrm = null; 
try 
{ 
fstrm = new 
FileOutputStream(savefile); 
ostrm = new 
BufferedOutputStream(fstrm); 
byte[] bytes 
= null; 
try 
{ 
bytes = docToSave.getBytes(); 
} 
catch(Exception e1) 
{ 
e1.printStackTrace(); 
} 
ostrm.write(bytes); 
} 
catch(IOException io) 
{ 
System.err.println("IOException: " + 
io.getMessage()); 
} 
finally 
{ 
try 
{ 
ostrm.flush(); 
fstrm.close(); 
ostrm.close(); 
} 
catch(IOException ioe) 
{ 
System.err.println("IOException: " + 
ioe.getMessage());
} 
} 
} 
} 
} 
else 
{ 
return; 
} 
} 
} 
class exitL implements ActionListener 
{ 
public void actionPerformed(ActionEvent e) 
{ 
System.exit(0); 
} 
} 
class copyL implements ActionListener 
{ 
public void actionPerformed(ActionEvent e) 
{ 
String selection = jta.getSelectedText(); 
StringSelection clipString = new StringSelection(selection); 
clipbd.setContents(clipString, clipString); 
} 
} 
class cutL implements ActionListener 
{ 
public void actionPerformed(ActionEvent e) 
{ 
String selection = jta.getSelectedText(); 
StringSelection clipString = new StringSelection(selection); 
clipbd.setContents(clipString, clipString); 
jta.replaceRange("", jta.getSelectionStart(), 
jta.getSelectionEnd()); 
} 
} 
class pasteL implements ActionListener 
{ 
public void actionPerformed(ActionEvent e) 
{ 
Transferable clipData = clipbd.getContents(notepad.this); 
try 
{ 
String clipString = 
(String)clipData.getTransferData( 
DataFlavor.stringFlavor); 
jta.replaceRange(clipString, 
jta.getSelectionStart(), jta.getSelectionEnd()); 
} 
catch(Exception ex) 
{ 
} 
} 
} 
class deleteL implements ActionListener 
{ 
public void actionPerformed(ActionEvent e)
{ 
String selection = jta.getSelectedText(); 
jta.replaceRange("", jta.getSelectionStart(), 
jta.getSelectionEnd()); 
} 
} 
class selectAllL implements ActionListener 
{ 
public void actionPerformed(ActionEvent e) 
{ 
jta.selectAll(); 
} 
} 
class findL implements ActionListener 
{ 
public void actionPerformed(ActionEvent e) 
{ 
String find = ""; 
find = JOptionPane.showInputDialog( 
"Find what: "); 
} 
} 
class findNextL implements ActionListener 
{ 
public void actionPerformed(ActionEvent e) 
{ 
} 
} 
class aboutL implements ActionListener 
{ 
public void actionPerformed(ActionEvent e) 
{ 
JOptionPane.showMessageDialog(null, 
"Notepad Developed By rohinn"); 
} 
} 
public notepad() 
{ 
setLayout(new BorderLayout()); 
file.add(jmi = new JMenuItem("New",KeyEvent.VK_N)); 
jmi.addActionListener(new newL()); 
file.add(jmi = new JMenuItem("Open",KeyEvent.VK_O)); 
jmi.addActionListener(new openL()); 
file.addSeparator(); 
file.add(jmi = new JMenuItem("Save",KeyEvent.VK_A)); 
jmi.addActionListener(new saveL()); 
file.add(jmi = new JMenuItem("Close",KeyEvent.VK_L)); 
jmi.addActionListener(new exitL()); 
file.setMnemonic(KeyEvent.VK_F); 
jmb.add(file); 
edit.add(jmi=new JMenuItem("Copy",KeyEvent.VK_C)); 
jmi.addActionListener(new copyL()); 
edit.add(jmi=new JMenuItem("Cut",KeyEvent.VK_U)); 
jmi.addActionListener(new cutL()); 
edit.add(jmi=new JMenuItem("Paste",KeyEvent.VK_S)); 
jmi.addActionListener(new pasteL()); 
edit.add(jmi=new JMenuItem("Delete",KeyEvent.VK_E));
jmi.addActionListener(new deleteL()); 
edit.addSeparator(); 
edit.add(jmi=new JMenuItem("SelectAll",KeyEvent.VK_S)); 
jmi.addActionListener(new selectAllL()); 
edit.setMnemonic(KeyEvent.VK_E); 
jmb.add(edit); 
search.add(jmi=new JMenuItem("Find",KeyEvent.VK_F)); 
jmi.addActionListener(new findL()); 
search.add(jmi=new JMenuItem("FindNext",KeyEvent.VK_T)); 
jmi.addActionListener(new findNextL()); 
search.setMnemonic(KeyEvent.VK_S); 
jmb.add(search); 
help.add(jmi=new JMenuItem("About",KeyEvent.VK_A)); 
jmi.addActionListener(new aboutL()); 
help.setMnemonic(KeyEvent.VK_H); 
jmb.add(help); 
add(jmb, BorderLayout.NORTH); 
toolBar.setFloatable(false); 
addButtons(toolBar); 
add(toolBar, BorderLayout.CENTER); 
add(jsp, BorderLayout.SOUTH); 
} 
protected void addButtons(JToolBar toolBar) 
{ 
JButton button = new JButton(new ImageIcon("images/new.gif")); 
button.setToolTipText("Create a new document"); 
button.addActionListener(new newL()); 
toolBar.add(button); 
JButton button1 = new JButton(new ImageIcon("images/open.gif")); 
button1.setToolTipText("Open a document"); 
button1.addActionListener(new openL()); 
toolBar.add(button1); 
JButton button2 = new JButton(new ImageIcon("images/save.gif")); 
button2.setToolTipText("Save the document"); 
button2.addActionListener(new saveL()); 
toolBar.add(button2); 
JButton button3 = new JButton(new ImageIcon("images/copy.gif")); 
button3.setToolTipText("Copy selected text"); 
button3.addActionListener(new copyL()); 
toolBar.add(button3); 
JButton button4 = new JButton(new ImageIcon("images/cut.gif")); 
button4.setToolTipText("Cut selected text"); 
button4.addActionListener(new cutL()); 
toolBar.add(button4); 
JButton button5 = new JButton(new ImageIcon("images/paste.gif")); 
button5.setToolTipText("Paste clipboard"); 
button5.addActionListener(new pasteL()); 
toolBar.add(button5); 
JButton button6 = new JButton(new ImageIcon("images/about.gif")); 
button6.setToolTipText("About application"); 
button6.addActionListener(new aboutL()); 
toolBar.add(button6);
} 
public static void main(String args[]) 
{ 
JFrame f = new JFrame(); 
notepad notepad = new notepad(); 
f.setTitle("rohinn Creation Notepad"); 
f.setBackground(Color.lightGray); 
f.getContentPane().add(notepad,BorderLayout.CENTER); 
f.setSize(800, 500); 
f.setVisible(true); 
} 
}
} 
public static void main(String args[]) 
{ 
JFrame f = new JFrame(); 
notepad notepad = new notepad(); 
f.setTitle("rohinn Creation Notepad"); 
f.setBackground(Color.lightGray); 
f.getContentPane().add(notepad,BorderLayout.CENTER); 
f.setSize(800, 500); 
f.setVisible(true); 
} 
}

More Related Content

PDF
COScheduler In Depth
PDF
Js 单元测试框架介绍
PPTX
NetBeans Plugin Development: JRebel Experience Report
RTF
Easy Button
PPT
C# Application program UNIT III
PPT
2012 JDays Bad Tests Good Tests
PDF
Testing, Performance Analysis, and jQuery 1.4
PDF
Server1
COScheduler In Depth
Js 单元测试框架介绍
NetBeans Plugin Development: JRebel Experience Report
Easy Button
C# Application program UNIT III
2012 JDays Bad Tests Good Tests
Testing, Performance Analysis, and jQuery 1.4
Server1

What's hot (20)

PDF
The Ring programming language version 1.9 book - Part 91 of 210
DOCX
Student management system
PDF
The Ring programming language version 1.5.3 book - Part 88 of 184
DOCX
201913046 wahyu septiansyah network programing
PDF
#JavaFX.forReal() - ElsassJUG
PDF
Construire une application JavaFX 8 avec gradle
PDF
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
DOCX
Ejemplo radio
PDF
Java 7 LavaJUG
PDF
First Steps. (db4o - Object Oriented Database)
PDF
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
PDF
33rd Degree 2013, Bad Tests, Good Tests
PDF
The Ring programming language version 1.5.3 book - Part 26 of 184
DOCX
Code red SUM
PDF
5. Ввод-вывод, доступ к файловой системе
DOCX
XTW_Import
KEY
How to Start Test-Driven Development in Legacy Code
PDF
The Ring programming language version 1.5.4 book - Part 78 of 185
DOCX
Wwe Management System
PPT
Simple API for XML
The Ring programming language version 1.9 book - Part 91 of 210
Student management system
The Ring programming language version 1.5.3 book - Part 88 of 184
201913046 wahyu septiansyah network programing
#JavaFX.forReal() - ElsassJUG
Construire une application JavaFX 8 avec gradle
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
Ejemplo radio
Java 7 LavaJUG
First Steps. (db4o - Object Oriented Database)
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
33rd Degree 2013, Bad Tests, Good Tests
The Ring programming language version 1.5.3 book - Part 26 of 184
Code red SUM
5. Ввод-вывод, доступ к файловой системе
XTW_Import
How to Start Test-Driven Development in Legacy Code
The Ring programming language version 1.5.4 book - Part 78 of 185
Wwe Management System
Simple API for XML
Ad

Viewers also liked (6)

PPT
Notepad
PPT
Word pad
PPS
Notepad Presentation Mca
PPT
Applications of computer
PPT
Application Of Computers
PPT
Microsoft word basics ppt
Notepad
Word pad
Notepad Presentation Mca
Applications of computer
Application Of Computers
Microsoft word basics ppt
Ad

Similar to Notepad (20)

PDF
PDF
How do I make my JTable non editableimport java.awt.; import j.pdf
PDF
package net.codejava.swing.mail;import java.awt.Font;import java.pdf
PDF
Hafitz_Rizki 201343500823 JMenuBar_JavaMsAccess_JavaGrade
DOCX
PDF
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
PPTX
Exceptions and errors in Java
PDF
Chat application in java using swing and socket programming.
PPTX
Java 104
DOCX
Java programming lab_manual_by_rohit_jaiswar
PDF
import javaxswing import javaawtevent import javai.pdf
DOC
Inheritance
DOC
PPTX
Binary patching for fun and profit @ JUG.ru, 25.02.2012
PDF
JJUG CCC 2011 Spring
PDF
You are to simulate a dispatcher using a priority queue system in C+.pdf
PDF
Convert the following program so that it uses JList instead of JComb.pdf
PPT
04_1.Exceptionssssssssssssssssssss..pptt
PDF
import java.awt.FlowLayout;import java.awt.event.KeyEvent;import.pdf
How do I make my JTable non editableimport java.awt.; import j.pdf
package net.codejava.swing.mail;import java.awt.Font;import java.pdf
Hafitz_Rizki 201343500823 JMenuBar_JavaMsAccess_JavaGrade
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
Exceptions and errors in Java
Chat application in java using swing and socket programming.
Java 104
Java programming lab_manual_by_rohit_jaiswar
import javaxswing import javaawtevent import javai.pdf
Inheritance
Binary patching for fun and profit @ JUG.ru, 25.02.2012
JJUG CCC 2011 Spring
You are to simulate a dispatcher using a priority queue system in C+.pdf
Convert the following program so that it uses JList instead of JComb.pdf
04_1.Exceptionssssssssssssssssssss..pptt
import java.awt.FlowLayout;import java.awt.event.KeyEvent;import.pdf

Notepad

  • 1. package test; import java.awt.*; import java.awt.event.*; import java.awt.datatransfer.*; import java.io.*; import javax.swing.*; import javax.swing.text.*; public class notepad extends JPanel { JTextArea jta = new JTextArea("", 24, 40); JScrollPane jsp = new JScrollPane(jta); JMenuBar jmb = new JMenuBar(); JMenu file = new JMenu("File"); JMenu edit = new JMenu("Edit"); JMenu search = new JMenu("Search"); JMenu help = new JMenu("Help"); JMenuItem jmi; JToolBar toolBar=new JToolBar(); Clipboard clipbd = getToolkit().getSystemClipboard(); class newL implements ActionListener { public void actionPerformed(ActionEvent e) { jta.setDocument(new PlainDocument()); } } class openL implements ActionListener { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showDialog(notepad.this, "Open file"); if(returnVal == JFileChooser.APPROVE_OPTION) { String file = fc.getSelectedFile().getPath(); if(file == null) { return; } try { Reader in = new FileReader(file); char[] buff = new char[4096]; int nch; while((nch = in.read(buff, 0, buff.length)) != -1) { jta.setDocument(new PlainDocument()); jta.append(new String(buff, 0, nch)); } } catch (IOException io) { System.err.println("IOException: " + io.getMessage()); } } else { return;
  • 2. } } } class saveL implements ActionListener { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showSaveDialog(notepad.this); if(returnVal == JFileChooser.APPROVE_OPTION) { String savefile = fc.getSelectedFile().getPath(); if(savefile == null) { return; } else { String docToSave = jta.getText(); if(docToSave != null) { FileOutputStream fstrm = null; BufferedOutputStream ostrm = null; try { fstrm = new FileOutputStream(savefile); ostrm = new BufferedOutputStream(fstrm); byte[] bytes = null; try { bytes = docToSave.getBytes(); } catch(Exception e1) { e1.printStackTrace(); } ostrm.write(bytes); } catch(IOException io) { System.err.println("IOException: " + io.getMessage()); } finally { try { ostrm.flush(); fstrm.close(); ostrm.close(); } catch(IOException ioe) { System.err.println("IOException: " + ioe.getMessage());
  • 3. } } } } } else { return; } } } class exitL implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } class copyL implements ActionListener { public void actionPerformed(ActionEvent e) { String selection = jta.getSelectedText(); StringSelection clipString = new StringSelection(selection); clipbd.setContents(clipString, clipString); } } class cutL implements ActionListener { public void actionPerformed(ActionEvent e) { String selection = jta.getSelectedText(); StringSelection clipString = new StringSelection(selection); clipbd.setContents(clipString, clipString); jta.replaceRange("", jta.getSelectionStart(), jta.getSelectionEnd()); } } class pasteL implements ActionListener { public void actionPerformed(ActionEvent e) { Transferable clipData = clipbd.getContents(notepad.this); try { String clipString = (String)clipData.getTransferData( DataFlavor.stringFlavor); jta.replaceRange(clipString, jta.getSelectionStart(), jta.getSelectionEnd()); } catch(Exception ex) { } } } class deleteL implements ActionListener { public void actionPerformed(ActionEvent e)
  • 4. { String selection = jta.getSelectedText(); jta.replaceRange("", jta.getSelectionStart(), jta.getSelectionEnd()); } } class selectAllL implements ActionListener { public void actionPerformed(ActionEvent e) { jta.selectAll(); } } class findL implements ActionListener { public void actionPerformed(ActionEvent e) { String find = ""; find = JOptionPane.showInputDialog( "Find what: "); } } class findNextL implements ActionListener { public void actionPerformed(ActionEvent e) { } } class aboutL implements ActionListener { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "Notepad Developed By rohinn"); } } public notepad() { setLayout(new BorderLayout()); file.add(jmi = new JMenuItem("New",KeyEvent.VK_N)); jmi.addActionListener(new newL()); file.add(jmi = new JMenuItem("Open",KeyEvent.VK_O)); jmi.addActionListener(new openL()); file.addSeparator(); file.add(jmi = new JMenuItem("Save",KeyEvent.VK_A)); jmi.addActionListener(new saveL()); file.add(jmi = new JMenuItem("Close",KeyEvent.VK_L)); jmi.addActionListener(new exitL()); file.setMnemonic(KeyEvent.VK_F); jmb.add(file); edit.add(jmi=new JMenuItem("Copy",KeyEvent.VK_C)); jmi.addActionListener(new copyL()); edit.add(jmi=new JMenuItem("Cut",KeyEvent.VK_U)); jmi.addActionListener(new cutL()); edit.add(jmi=new JMenuItem("Paste",KeyEvent.VK_S)); jmi.addActionListener(new pasteL()); edit.add(jmi=new JMenuItem("Delete",KeyEvent.VK_E));
  • 5. jmi.addActionListener(new deleteL()); edit.addSeparator(); edit.add(jmi=new JMenuItem("SelectAll",KeyEvent.VK_S)); jmi.addActionListener(new selectAllL()); edit.setMnemonic(KeyEvent.VK_E); jmb.add(edit); search.add(jmi=new JMenuItem("Find",KeyEvent.VK_F)); jmi.addActionListener(new findL()); search.add(jmi=new JMenuItem("FindNext",KeyEvent.VK_T)); jmi.addActionListener(new findNextL()); search.setMnemonic(KeyEvent.VK_S); jmb.add(search); help.add(jmi=new JMenuItem("About",KeyEvent.VK_A)); jmi.addActionListener(new aboutL()); help.setMnemonic(KeyEvent.VK_H); jmb.add(help); add(jmb, BorderLayout.NORTH); toolBar.setFloatable(false); addButtons(toolBar); add(toolBar, BorderLayout.CENTER); add(jsp, BorderLayout.SOUTH); } protected void addButtons(JToolBar toolBar) { JButton button = new JButton(new ImageIcon("images/new.gif")); button.setToolTipText("Create a new document"); button.addActionListener(new newL()); toolBar.add(button); JButton button1 = new JButton(new ImageIcon("images/open.gif")); button1.setToolTipText("Open a document"); button1.addActionListener(new openL()); toolBar.add(button1); JButton button2 = new JButton(new ImageIcon("images/save.gif")); button2.setToolTipText("Save the document"); button2.addActionListener(new saveL()); toolBar.add(button2); JButton button3 = new JButton(new ImageIcon("images/copy.gif")); button3.setToolTipText("Copy selected text"); button3.addActionListener(new copyL()); toolBar.add(button3); JButton button4 = new JButton(new ImageIcon("images/cut.gif")); button4.setToolTipText("Cut selected text"); button4.addActionListener(new cutL()); toolBar.add(button4); JButton button5 = new JButton(new ImageIcon("images/paste.gif")); button5.setToolTipText("Paste clipboard"); button5.addActionListener(new pasteL()); toolBar.add(button5); JButton button6 = new JButton(new ImageIcon("images/about.gif")); button6.setToolTipText("About application"); button6.addActionListener(new aboutL()); toolBar.add(button6);
  • 6. } public static void main(String args[]) { JFrame f = new JFrame(); notepad notepad = new notepad(); f.setTitle("rohinn Creation Notepad"); f.setBackground(Color.lightGray); f.getContentPane().add(notepad,BorderLayout.CENTER); f.setSize(800, 500); f.setVisible(true); } }
  • 7. } public static void main(String args[]) { JFrame f = new JFrame(); notepad notepad = new notepad(); f.setTitle("rohinn Creation Notepad"); f.setBackground(Color.lightGray); f.getContentPane().add(notepad,BorderLayout.CENTER); f.setSize(800, 500); f.setVisible(true); } }