You are on page 1of 14

ABSTRACT

JPad is a basic text editor that you can use to create simple documents. The most common use for JPad is to view or edit text files, but many users find this editor as a simple tool for creating Web pages.Because,normally the editor supports only very basic formatting, you cannot accidentally save special formatting in documents that need to remain pure text. This is especially useful when creating HTML documents for a Web page because special characters or other formatting may not appear in your published Web page or may even cause errors.You can save JPad files as a text, html, Java extension. This JPad conatins different menus to give more convenience to the user. The menus like File,Edit,Process,and Look& Feel. This JPad provides various graphical icons to represent the frequently used menu items. These formats provide you greater flexibility when working with documents that use different character sets.

INTRODUCTION: A text editor is a type of program used for editing plain text files.Text editors are often provided with operating systems or software development packages, and can be used to change configuration files and programming language source code. Some text editors are small and simple, while others offer a broad and complex range of functionality. For example, Unix and Unix-like operating systems have the vi editor (or a variant), but many also include the Emacs editor. Microsoft Windows systems come with the very simple Notepad, though many peopleespecially programmersprefer to use one of many other Windows text editors with more features. The editing process often begins with the author's idea for the work itself, continuing as a collaboration between the author and the editor as the work is created. As such, editing is a practice that includes creative skills, human relations, and a precise set of methods.Notepad is a common text-only (plain text) editor. The resulting filestypically saved with the .txt extensionhave no format tags or styles, making the program suitable for editing system files that are to be used in a DOS environment. In Jpad the file menu contains new, open, save and exit menu items. In Jpad contains a menu called Look & feel. It provides a facilitate to change the appearance of the window. The edit menu contains various menu items such as cut, copy, and paste.

To cut text so you can move it to another location, select the text, and then on the Edit menu click Cut. To copy text so you can paste it in another location, select the text, and then on the Edit menu click Copy. To paste text you have cut or copied, place the cursor where you want to paste the text, and then on the Edit menu click Paste.

CODING: import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; import javax.swing.border.*; import javax.swing.undo.*; /*<applet code="JPad" height=500 width=500> </applet>*/ public class JPad extends JFrame implements ActionListener,ItemListener { JMenuBar jmb; JMenu file,edit,process,look; JMenuItem f1,f2,f3,f4; JMenuItem e1,e2,e3; JMenuItem p1,p2; JRadioButtonMenuItem laf1,laf2,laf3; JTextArea jta1,jta2; JTextField jt; JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11; JScrollPane jsp1,jsp2; FileDialog fd1,fd2; UIManager.LookAndFeelInfo looks[]=UIManager.getInstalledLookAndFeels(); final UndoManager undoManager=new UndoManager(); String cutstr,c,strings[]={"Metal","Motif","Windows"}; int start,end; public JPad() { super("JPad 1.0"); JPanel jp=(JPanel)getContentPane(); jp.setLayout(new BorderLayout()); jmb=new JMenuBar(); file=new JMenu("File"); file.setMnemonic('F'); jmb.add(file);

f1=new JMenuItem("New..."); f1.setMnemonic('N'); f1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,ActionEvent.CTRL_MASK )); file.add(f1); f1.addActionListener(this); f2=new JMenuItem("Open..."); f2.setMnemonic('O'); f2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,ActionEvent.CTRL_MASK )); file.add(f2); f2.addActionListener(this); file.addSeparator(); f3=new JMenuItem("Save..."); f3.setMnemonic('S'); f3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.CTRL_MASK )); file.add(f3); f3.addActionListener(this); file.addSeparator(); f4=new JMenuItem("Exit..."); f4.setMnemonic('x'); file.add(f4); f4.addActionListener(this); edit=new JMenu("Edit"); file.setMnemonic('E'); jmb.add(edit); e1=new JMenuItem("Cut"); e1.setMnemonic('t'); e1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,ActionEvent.CTRL_MAS K)); edit.add(e1); e1.addActionListener(this); e2=new JMenuItem("Copy"); e2.setMnemonic('C');

e2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.CTRL_MAS K)); edit.add(e2); e2.addActionListener(this); edit.addSeparator(); e3=new JMenuItem("Paste"); e3.setMnemonic('P'); e3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,ActionEvent.CTRL_MAS K)); edit.add(e3); e3.addActionListener(this); process=new JMenu("Process"); process.setMnemonic('r'); jmb.add(process); p1=new JMenuItem("Compile"); p1.setMnemonic('m'); p1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M,ActionEvent.CTRL_MAS K)); process.add(p1); p1.addActionListener(this); p2=new JMenuItem("Run"); p2.setMnemonic('R'); p2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,ActionEvent.CTRL_MAS K)); process.add(p2); p2.addActionListener(this); look=new JMenu("Look & Feel"); look.setMnemonic('L'); jmb.add(look); laf1=new JRadioButtonMenuItem("Metal"); look.add(laf1); laf1.addItemListener(this); laf2=new JRadioButtonMenuItem("Motif"); look.add(laf2); laf2.addItemListener(this);

laf3=new JRadioButtonMenuItem("Windows"); look.add(laf3); laf3.addItemListener(this); ButtonGroup group=new ButtonGroup(); group.add(laf1); group.add(laf2); group.add(laf3); setJMenuBar(jmb); JToolBar jtb=new JToolBar(); jtb.setBorder(new BevelBorder(BevelBorder.RAISED,Color.blue,Color.blue,Color.blue,Color.blue)); jp.add(jtb,"North"); b1=new JButton(new ImageIcon("new.jpg")); b1.setToolTipText("New"); b1.addActionListener(this); jtb.add(b1); b2=new JButton(new ImageIcon("open.jpg")); b2.setToolTipText("Open"); b2.addActionListener(this); jtb.add(b2); b3=new JButton(new ImageIcon("save.jpg")); b3.setToolTipText("Save"); b3.addActionListener(this); jtb.add(b3); jtb.addSeparator(); b4=new JButton(new ImageIcon("undo.jpg")); b4.setToolTipText("Undo"); b4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { undoManager.undo(); } catch(CannotUndoException ex) { System.out.println("Can't undo"); } }

}); jtb.add(b4); b5=new JButton(new ImageIcon("redo.jpg")); b5.setToolTipText("Redo"); b5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { undoManager.redo(); } catch(CannotUndoException ex) { System.out.println("Can't redo"); } } }); jtb.add(b5); jtb.addSeparator(); b6=new JButton(new ImageIcon("cut.jpg")); b6.setToolTipText("Cut"); b6.addActionListener(this); jtb.add(b6); b7=new JButton(new ImageIcon("copy.jpg")); b7.setToolTipText("Copy"); b7.addActionListener(this); jtb.add(b7); b8=new JButton(new ImageIcon("paste.jpg")); b8.setToolTipText("Paste"); b8.addActionListener(this); jtb.add(b8); b9=new JButton("About"); b9.addActionListener(this); jtb.add(b9); jta1=new JTextArea(); jta1.setBorder(BorderFactory.createLoweredBevelBorder()); jta1.setFont(new Font("Arial",Font.PLAIN,14)); jta1.setSelectedTextColor(Color.red); jta1.getDocument().addUndoableEditListener(undoManager); jsp1=new JScrollPane(jta1,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,

JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); jp.add(jsp1,"Center"); public static void main(String args[])throws Exception { JPad n=new JPad(); n.setVisible(true); n.setSize(800,600); n.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); } public void actionPerformed(ActionEvent e) { if((e.getSource()==f1)||(e.getSource()==b1)) { jta1.setText(" "); String temp=jta1.getText(); setTitle("JPad 1.0-New File"); } if((e.getSource()==f2)||(e.getSource()==b2)) { fd1=new FileDialog(this,"Opan a file",FileDialog.LOAD); fd1.setFile("*.*"); fd1.show(); try { File fr=new File(fd1.getDirectory()+fd1.getFile()); FileInputStream fis=new FileInputStream(fr); DataInputStream dis=new DataInputStream(fis); jta1.setText(""); for(int i=0;i<fr.length();i++) jta1.append(String.valueOf((char)dis.read())); } catch(Exception e1) { e1.printStackTrace();

} } if((e.getSource()==f3)||(e.getSource()==b3)) { fd2=new FileDialog(this,"Save a file",FileDialog.SAVE); fd2.setFile("*.*"); fd2.show(); try { File fr1=new File(fd2.getDirectory()+fd2.getFile()); FileOutputStream fos=new FileOutputStream(fr1); DataOutputStream dos=new DataOutputStream(fos); RandomAccessFile rafs=new RandomAccessFile(fr1,"rw"); c=jta1.getText().trim(); int d=c.length(); int kk=0; for(int mn=0;mn<d;mn++) if(c.charAt(mn)=='\r')kk++; byte n[]=new byte[d-kk]; int i,l; for(i=0,l=0;i<d;i++) { if(c.charAt(i)!='\r') if(c.charAt(i)!='Y') { n[l]=(byte)c.charAt(i); l++; } } rafs.write(n); rafs.close(); } catch(Exception e2) { e2.printStackTrace(); } } if(e.getSource()==f4) { System.exit(0); } if(e.getSource()==b9) {

JOptionPane.showMessageDialog((Component)null,"JPad 1.0\n project done by VIJAYABHASKAR","About JPad 1.0",JOptionPane.PLAIN_MESSAGE); } if((e.getSource()==e1)||(e.getSource()==b6)) { cutstr=jta1.getSelectedText(); start=jta1.getSelectionStart(); end=jta1.getSelectionEnd(); jta1.replaceRange(" ",start,end); } if((e.getSource()==e2)||(e.getSource()==b7)) { cutstr=jta1.getSelectedText(); } if((e.getSource()==e3)||(e.getSource()==b8)) { jta1.insert(cutstr,jta1.getCaretPosition()); } if((e.getSource()==p1)||(e.getSource()==p2)||(e.getSource()==jt)/*||(e.getSource()==b10)|| (e.getSource()==b11)*/) { jta2.setText(" "); try { String s=jt.getText(); Process process=Runtime.getRuntime().exec(s); InputStream ips=process.getErrorStream(); int i; while((i=ips.read())!=-1) jta2.append(String.valueOf((char)i)); if(process.exitValue()==0) { InputStream ips1=process.getInputStream(); int j; if(ips1.available()!=0) while((j=ips1.read())!=-1) jta2.append(String.valueOf((char)j)); } else { jta2.append("Congrades"); } }

catch(Exception ie) { ie.printStackTrace(); } }} public void itemStateChanged(ItemEvent ie) { if(laf1.isSelected()) { try{ UIManager.setLookAndFeel(looks[0].getClassName()); SwingUtilities.updateComponentTreeUI(this); } catch(Exception el) { el.printStackTrace(); }} if(laf2.isSelected()) { try{ UIManager.setLookAndFeel(looks[1].getClassName()); SwingUtilities.updateComponentTreeUI(this); } catch(Exception el) { el.printStackTrace(); }} if(laf3.isSelected()) { try { UIManager.setLookAndFeel(looks[2].getClassName()); SwingUtilities.updateComponentTreeUI(this); } catch(Exception el) { el.printStackTrace(); } } } }

OUTPUT: SCREEN SHOTS:

Fig: 1.0 Creating a new file

Fig:1.1 Save the file

Fig 1.3: Look & Feel of JPad.

CONCLUSION: JPad is a compact general-purpose text editor. It is Simple to use, the user can interact easily. Use JPad to easily edit any kind of plain text file. In feature JPad having a facility to execute the Java programs also. Finally, JPad has all the essential features to make text editing a breeze.

You might also like