P. 1
Notepad

Notepad

|Views: 9|Likes:
Published by kirandeeps_2

More info:

Published by: kirandeeps_2 on Aug 02, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

08/02/2012

pdf

text

original

import import import public {

javax.swing.*; java.io.*; java.awt.event.*; class Notepad public static void main(String[] args) { new Demo(); }

} class Demo extends JFrame implements ActionListener { JMenuBar menu1; JMenu m1,m2; JMenuItem m11,m12,m13,m23,m21,m22; String sr1,name1; FileOutputStream fos; File f; char[] sr; int j=0; JTextArea ta= new JTextArea(); Demo() { setSize(1366,718); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(null); menu1= new JMenuBar(); m1= new JMenu("File"); m2= new JMenu("Edit"); m11= new JMenuItem("New"); m12= new JMenuItem("Open"); m13= new JMenuItem("Save"); m21= new JMenuItem("Cut"); m22= new JMenuItem("Copy"); m23= new JMenuItem("Paste"); menu1.setBounds(0,0,1366,20); ta.setBounds(0,20,1366,698); add(menu1); menu1.add(m1); menu1.add(m2); m1.add(m11); m1.addSeparator(); m1.add(m12); m1.addSeparator(); m1.add(m13); m2.add(m21); m2.addSeparator(); m2.add(m22); m2.addSeparator(); m2.add(m23); add(ta); m11.addActionListener(this); m12.addActionListener(this); m13.addActionListener(this); m21.addActionListener(this); m22.addActionListener(this); m23.addActionListener(this); } public void actionPerformed(ActionEvent ae)

read(). String s="". if(i== JFileChooser.getSelectedFile().getText().getSource()==m22) { copy().showOpenDialog(new JFrame()). //int j=0.getSource()==m11) { ta.{ if(ae. int i= select.getPath()+".setFileFilter(new Filefilter()).toCharArray(). } else if(ae. } else if(ae.getSource()==m13) { save(). } else if(ae. select. int i= select.getSource()==m23) { paste().setFileFilter(new Filefilter()).getSource()==m21) { cut(). while(fis. if(f1. File f1= new File(name1).exists()) .showSaveDialog(new JFrame()).APPROVE_OPTION) { try{ String name= select. sr=ta. } } public void save() { JFileChooser select= new JFileChooser().APPROVE_OPTION) { try{ name1= select.available()>0) { s=s+(char)fis. } else if(ae. fis = new FileInputStream(name).txt" . } else if(ae.getSource()==m12) { open(). FileInputStream fis.setText(s).getSelectedFile(). } }catch(Exception e){} ta. } } public void open() { JFileChooser select= new JFileChooser().getPath(). select. if(i== JFileChooser.setText("").

out.endsWith(". int b= ta.OK_OPTION . } public String getDescription() { return "text files". } else { save1().print(name1).} } } public void cut() { sr1= ta. int a= ta.{ int a=JOptionPane.filechooser. j++.getSelectionStart(). ta.getSelectedText().replaceRange("". b).createNewFile().out.JOptionPane.FileFilter { public boolean accept(File f) { return f.CANCEL_OPTION). } if(a==JOptionPane.getSelectedText(). while(j<sr. if(a==JOptionPane.swing. "Do you want to overwrite ?". } public void paste() { int a1=ta.getName().OK_OPTION) { save1().showConfirmDialog(null . } public void save1() { try{ System.CANCEL_OPTION) return. f. fos=new FileOutputStream(name1).write(sr[j]).txt").getSelectionStart().replaceSelection(sr1). } . } public void copy() { sr1=ta. f=new File(name1). a."enter ok for confirmation". ta.length) { fos. } }catch(Exception e){} } } class Filefilter extends javax. } }catch(Exception e){System.getSelectionEnd().print(e).JOptionPane.isDirectory()||f.

} .

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->