Your SlideShare is downloading. ×

Ex11 mini project

2,921

Published on

Published in: Education, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,921
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
172
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Elanthendral.M (HDCA) 11.Develop a programmer’s editor in java that supports syntaxhighlighting, compilation support ,debugging support,ect…Aim :- To Develop a programmer’s editor in java that supports Syntax Highlighting , compilation support , Debugging support.Algorithm:-I Syntax Highlighting 1.1 Definition:- Definition Syntax highlighting is a feature of some text editors, that display text- especially Source code in different colors and fonts according to the category of terms. 1.2 Introduction:- i. This feature eases writing in a structured language such as a programming language or a markup language as both structures and syntax error are visually distinct. ii. Highlighting does not affect the meaning of the text itself; it’s made only for human readers/editors iii. Syntax highlighting is a form of secondary notation, since the highlights are not part of the text meaning, but serve to reinforce it. Some editor also integrate syntax highlighting with other features, such Highlighting with other features , such as spell checking or code folding , as aids to editing which are external to the language. 1.3 Procedure:- i. Create a repository of sorts that would store all of the style changes that must be made to the document, and when the write lock is lifted , perform the changes. I’ve made the repository , and I’ve tried to make the changes just before painting the control , but that doesn’t work .Can anyone suggest a better time to perform the changes?
  • 2. ii. Start up a new thread that waits for the write lock to be lifted , and , when it is performs the changes . I’m not extremely familiar with threading in java , through , so anyone who wants to give me a solution using this method need to be very explicit and verbose. iii. Any other simple way that doesn’t involve using something other than JTextArea.II Compilation 2. 1 Definition:- i. A compiler is a computer program (or set of programs) that transforms source code written in a programming language (the source language) into another computer language (the target language, often having a binary form known as object code). The most common reason for wanting to transform source code is to create an executable program ii. Translate a (high level) language program into an equivalent assembly language program. 2.2Java compilation i. Source code java is compiled into “bytecode” instead of machine code. ii. bytecode is executed by the virtual machine , it is device independent. iii. Bytecode : assembly + types + object oriented layer. 2.3 Introduction:- 2.4Two main parts the compilation i. To understand the program. ii. To translate it into machine code. 2.4.1 Understanding programs Procedure :- At the beginning a program is just a text: i. Cut the sequence into words(lexical analysis) ii. Organize words into sentences(syntactic analysis,parsing) iii. Encodes the meaning of sentences Close to the understanding of natural languages , for natural language , start with aflow of sounds
  • 3. 2.4.2 Generate machine programs Procedure :- i. Produce machine code realizing the original program. ii. Decompose complex abstract operations of the program into sequences of simple , basic machine instruction. iii. Optimize the program.III Debugging :-3. Definition:- A Degugger or Debugging tool is a computer program that is used to test and debug other programs (the “target” program ). The code to be examined might alternatively be running on an instruction set simulator(ISS), a technique that allows great power in its ability to halt when specific conditions are encountered but which will typically be somewhat slower than executing slower than executing the code directly on the appropriate (or the same). Some debugger offer two modes of operation – full or partial simulation , to limit this impact.IV Tool Tips:- i. Creating a tool tip for any Jcomponent object is easy .use the Picture Picture name Tooltip name NEW new.gif Open open.gif Save save.gif Copy copy.gif Cut cut.gif Past past.gif setToolTipText method to set up a tool tip for the component . ii. In this program we use the this type of the ToolTip;
  • 4. V Task Manager In this project we use task manager5.1 how to get the running applications in windows task manager usingjava Why are you doing System type stuff using Java? It is not designed for it. If you want a command line command to get the "application" list that appears in TaskManager5.2 What is task manager:- i. Task Manager provides information about programs and processes running on your computer. It also displays the most commonly used performance measures for processes.
  • 5. ii. You can use Task Manager to monitor key indicators of your computers performance. You can see the status of the programs that are running and end programs that have stopped responding. You can also assess the activity of running processes using as many as fifteen parameters, and see graphs and data on CPU and memory usage. iii. In addition, if you are connected to a network, you can view network status and see how your network is functioning. iv. If you have more than one user connected to your computer, you can see who is connected, what they are working on, and you can send them a message.5.3 Programs that are running i. The Applications tab shows the status of the programs running on your computer. ii. On this tab, you can end, switch to, or start a program.5.4 Processes that are running i. The Processes tab shows information about the processes running on your computer. ii. For example, you can display information on CPU and memory usage, page faults, handle count, and a number of other parameters.5.5 Performance measures The Performance tab displays a dynamic overview of your computers performance, including: i. Graphs for CPU and memory usage. ii. Totals for the number of handles, threads, and processes running on your computer. iii. Totals, in kilobytes, for physical, kernel, and commit memory.5.6 Viewing Network performance i. The Networking tab displays a graphical representation of network performance. It provides a simple, qualitative indicator that shows the status of the network(s) that are running on your computer. The Networking tab is displayed only if a network card is present. ii. On this tab, you can view the quality and availability of your network connection, whether you are connected to one or more than one network.
  • 6. 5.7Monitoring Sessions i. The Users tab displays users who can access this computer, and session status and names. Client Name specifies the name of the client computer using the session, if applicable. Session provides a name for you to use to perform such tasks as sending another user a message or connecting to another user’s session. ii. The Users tab is displayed only if the computer you are working on has Fast User Switching enabled, and is a member of a workgroup or is a standalone computer. The Users tab is unavailable on computers that are members of a network domain.Program :-import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;/** * This class demonstrates Debugging,Syntax HighLighting,Compling * @author E.Annal Sheeba Rani * @Version jdk1.6 */public class sw1 extends JFrame implements ActionListener,KeyListener{ // A frame with text field and Label fieldJToolBar tb = new JToolBar(); // icf & b1 an array of values.String icf[] ={"new.gif","open.gif","save.gif","cut.gif","copy.gif","paste.gif"};
  • 7. // b1 represents for TooltipString bl[] = {"New","Open","Save","Cut","Copy","Paste"}; // Demonstrate a one-dimensional arrayImageIcon ic[] = new ImageIcon[icf.length]; // use a lable to display syntax highlightingLabel l1 = new Label("Syntax Highlighting");JButton mbl[] = new JButton[icf.length]; // set up manu barMenuBar mbar = new MenuBar();Menu a = new Menu("File");Menu b = new Menu("Edit");Menu c = new Menu("Font");Menu d = new Menu("Font-Size");Menu f = new Menu("System");int fsize = 13; // assigns fsize theValue 13JTextArea ta,ta1;JScrollPane js1;// create a fontList using GraphicsEnvironmentString fontList[] =GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();// create MenuItemMenuItem m[] = new MenuItem[fontList.length];MenuItem fs[] = new MenuItem[600];MenuItem a1 = new MenuItem("New");MenuItem a2 = new MenuItem("Open");MenuItem a3 = new MenuItem("Save");MenuItem a4 = new MenuItem("Save as");
  • 8. MenuItem a5 = new MenuItem("-");MenuItem a6 = new MenuItem("Exit");MenuItem b1 = new MenuItem("Cut");MenuItem b2 = new MenuItem("Copy");MenuItem b3 = new MenuItem("Paste");MenuItem d1 = new MenuItem("Compile");MenuItem d2 = new MenuItem("Run");String ck="";int i;public sw1(){ super("Java Editor"); //set title setSize(1024,768); //assign a layoutsize setLayout(null); ta=new JTextArea(10,10); js1=new JScrollPane(ta); ta1=new JTextArea(5,60); add(js1);add(ta);add(ta1);add(tb); a.add(a1);add(l1); a.add(a2); a.add(a3); a.add(a4); a.add(a5); a.add(a6); b.add(b1); b.add(b2); b.add(b3); f.add(d1); f.add(d2); mbar.add(a); mbar.add(b); mbar.add(c); mbar.add(d); mbar.add(f); setMenuBar(mbar);// loop for FontList
  • 9. for (i = 0; i < fontList.length; i++ ) { m[i] = new MenuItem(fontList[i]); m[i].addActionListener(this); m[i].setActionCommand(""+i); c.add(m[i]); }// loop for MenuItemfor (i = 8; i <=90 ; i+=2) { fs[i] = new MenuItem(String.valueOf(i)); fs[i].addActionListener(new fs()); d.add(fs[i]); }//loop for ImageIcone for( i =0;i<bl.length;i++) { ic[i ]= new ImageIcon(icf[i]); mbl[i] = new JButton(ic[i]); mbl[i].setToolTipText(bl[i]); mbl[i].addActionListener(this); mbl[i].setActionCommand("z"+i); if(i==3) tb.addSeparator(); tb.add(mbl[i]); } tb.reshape(0,0,500,35); ta.reshape(5,40,1005,500);
  • 10. js1.reshape(5,4,100,35); // set foregroundcolor for l1 that is Syntax Highlighting l1.setForeground(Color.green); // set foregroundcolor for ta that is text area ta.setForeground(Color.blue); l1.reshape(400,550,130,30); ta1.reshape(5,600,1005,200); ta1.setForeground(Color.red);add(tb); add(ta); add(js1); add(l1); // This Listener can performed in wh object a6.addWindowListener(new wh()); // This Listener can be performed in this objecta1.addActionListener(this);a2.addActionListener(this);a3.addActionListener(this);a4.addActionListener(this); // This Listener can be performed in wc objecta5.addActionListener(new wc());b1.addActionListener(new wc());b2.addActionListener(new wc());b3.addActionListener(new wc());d1.addActionListener(new wc());
  • 11. d2.addActionListener(new wc()); ta.addKeyListener(this); show();}//set button actionpublic class wh extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0);}} // an ActionListener that sets the FontSizepublic class fs implements ActionListener { public void actionPerformed(ActionEvent e) {fsize = Integer.parseInt(e.getActionCommand()); System.out.println(fsize);}}public class wc implements ActionListener {public void actionPerformed(ActionEvent e) { // create button actionsString cmd= e.getActionCommand(); // associate actions with buttonsif (cmd.equals("Exit")) System.exit(0);if (cmd.equals("Cut")) ta.cut();if (cmd.equals("Copy")) ta.copy();if (cmd.equals("Paste")) ta.paste();
  • 12. if (cmd.equals("Save")){}if (cmd.equals("Compile")) { try {Runtime rt= Runtime.getRuntime();Process p= rt.exec("taskmgr.exe"); } catch(Exception ea) { System.out.println("Error");} } } } public void keyReleased(KeyEvent ke){} public void keyPressed(KeyEvent ke){} public void keyTyped(KeyEvent ke) { // create a KeyPressed , KeyReleased, Key Typed Character k = ke.getKeyChar(); int mk = (int) k; System.out.println(mk); ck += k; // create KeyReleased action if (ck.equals("for ")) { ta1.setText(""); ta1.append("for(var=init;condition;incr/decr)n"); ta1.append("{n"); ta1.append(" set of statements;n"); ta1.append("}n"); ck=""; }
  • 13. if (ck.equals("if ")) { ta1.setText(""); ta1.append("if (condition)n"); ta1.append("{n"); ta1.append(" set of statements;n"); ta1.append("}n"); ta1.append("elsen"); ta1.append("{n"); ta1.append(" set of statements;n"); ta1.append("}n"); ck = ""; }if (ck.equals("do ")) { ta1.setText(""); ta1.append("don"); ta1.append("{n"); ta1.append(" set of statements;n"); ta1.append("}n"); ta1.append("while (condition);n"); ck = ""; }if (ck.equals("while ")) { ta1.setText(""); ta1.append("while(condition)n"); ta1.append("{n"); ta1.append(" set of statements;n"); ta1.append("}n"); ck = ""; } if (mk == 10 || mk == 32 || mk == 8 || mk == 9) ck ="";} //to create Button Link
  • 14. public void actionPerformed(ActionEvent ae){ String s1 = (String) ae.getActionCommand();int ck1=1; System.out.println(s1);if (s1.equals("z0")) { ta.setText("");ck1=0; }if (s1.equals("z3")) { ta.cut();ck1=0; }if (s1.equals("z4")) { ta.copy();ck1=0; }if (s1.equals("z5")) { ta.paste();ck1=0; }if (s1.equals("z1")) {// for open a file menu FileDialog fx = new FileDialog(this,"Open a File",FileDialog.LOAD); fx.setDirectory("d:jeditor"); fx.setFile("*.*"); fx.show(); String mfname=fx.getDirectory()+fx.getFile(); setTitle(mfname); File fx1=new File(mfname);
  • 15. try { FileInputStream fis=new FileInputStream(fx1); int fsize=(int) fx1.length(); byte d[] =new byte[fsize]; fis.read(d); ta.setText(""); ta.setText(new String(d)); } catch(Exception ex){}; ck1=0;}if (s1.equals("z2")) { // for open a save menu bar FileDialog f=new FileDialog(this,"Save a File",FileDialog.SAVE); f.setDirectory("d:jeditor"); f.setFile("*.java"); f.show(); String fname=f.getDirectory()+f.getFile(); setTitle(fname); File f1=new File(fname); try { FileOutputStream fos=new FileOutputStream(f1); String t=ta.getText(); int fsize=t.length(); byte[] d=new byte[fsize]; t.getBytes(0,fsize,d,0); fos.write(d); fos.close(); } catch(Exception e){}; ck1=0;}
  • 16. if ((s1.compareTo("Open") != 0) && (s1.compareTo("Save")) != 0 &&(s1.compareTo("New") != 0) && (s1.compareTo("Save as") != 0 &&(ck1 == 1))) { int x = Integer.parseInt(ae.getActionCommand()); String fname = fontList[x]; Font f1 = new Font(fname,Font.BOLD,fsize); ta.setFont(f1); }if (s1.equals("Open")){ // for open a open menu bar FileDialog fx = new FileDialog(this,"Open a File",FileDialog.LOAD); fx.setDirectory("d:jeditor"); fx.setFile("*.*"); fx.show(); String mfname=fx.getDirectory()+fx.getFile(); setTitle(mfname); File fx1=new File(mfname);try { FileInputStream fis=new FileInputStream(fx1); int fsize=(int) fx1.length(); byte d[] =new byte[fsize]; fis.read(d); ta.setText(""); ta.setText(new String(d)); } catch(Exception ex){};}if (s1.equals("New")){ ta.setText("");}
  • 17. if (s1.equals("Save") || s1.equals("Save as")){ // for open a save or saveas menu bar FileDialog f=new FileDialog(this,"Save a File",FileDialog.SAVE); f.setDirectory("d:jeditor"); f.setFile("*.java"); f.show(); String fname=f.getDirectory()+f.getFile(); setTitle(fname); File f1=new File(fname); try { FileOutputStream fos=new FileOutputStream(f1); String t=ta.getText(); int fsize=t.length(); byte[] d=new byte[fsize]; t.getBytes(0,fsize,d,0); fos.write(d); fos.close(); } catch(Exception e){};}}public static void main(String args[]){ sw1 app = new sw1();}}
  • 18. Out put:-The output layoutThe file menu out put:- In this file menu we can do the following performances. there are:- i. Create a New file ii. Open a file
  • 19. iii. Save a file iv. Save as a file v. ExitPerformances for the file menu:-1: create a new file To create our new file , we can do following instruction 1. On the File menu, click New. 2. In the New Document task pane, under New, click From existing document. 3. Click the document you want to create a new document from. If you want to open a document that was saved in a different folder, locate and open the folder. 4. Click Create New. This document is created in the folder that contains the original document.2. Open a file To open a file , we can do following instruction 1. click File, and then click Open. 2. In the Look in list, click the drive, folder, or Internet location that contains the file you want to open. 3. In the folder list, locate and open the folder that contains the file. 4. Click the file, and then click Open.
  • 20. I.Save a file • On the File menu, click Save. • In the File name box, enter a new name for the file. • Click Save.Saveas a file 1. On the File menu, click Save as. 2. In the File name box, enter a new name for the file. 3. Click the Save as type drop-down list, and then click the file format that you want the file saved in.The out put for edit menu  The edit menu is also perform the following Idem There are:- i. Cut ii. Copy iii. Paste
  • 21. II. Copy a file 1. On the Standard toolbar, click Open . 2. Click a shortcut on the Places Bar, or in the Look in box, click the drive or folder that contains the file you want to copy. 3. In the folder list, locate and open the folder that contains the file you want to copy. 4. Right-click the file you want to copy, and then click Copy on the shortcut menu. 5. In the Look in box, click the drive or folder you want to copy the file to. 6. In the folder list, locate and open the folder you want to copy the file to. 7. Right-click anywhere in the folder list (make sure your pointer is not resting over a file in the list), and then click Paste on the shortcut menu.III.Cut and Paste a file 1. On the Standard toolbar, click Open . 2. Click a shortcut on the Places Bar, or in the Look in box, click the drive or folder that contains the file you want to move. 3. In the folder list, locate and open the folder that contains the file you want to move. 4. Right-click the file you want to move, and then click Cut on the shortcut menu. 5. In the Look in box, click the drive or folder you want to move the file to. 6. In the folder list, locate and open the folder you want to move the file to. 7. Right-click anywhere in the folder list (make sure your pointer is not resting over a file in the list), and then click Paste on the shortcut menu.The output for syntaxhighlighting IF WE WANT THE OUTPUT FOR syntaxhighlighting WE FOLLOW THEFOLLOWING COMMANDS:-AT FIRST WE TYPE THE WORD ,FOR EXAMPLE WE WANT THE SYNTAX FOR ‘if’  Type the if in text area  Then pressed the spaces bar  Then syntax can be apper in the syntaxhighligthing text.
  • 22. The out put for system Procedure for compilation :-  First write a program.  Then click systemcompile.  The Task Manager Dialog box can be opened.  Then click filecompile.
  • 23.  Task Manager dialog box can be apper. Then go to file menu in the Task Manager.
  • 24.  Select NEW TASK(RUN…) ,then Run dialog box can be apper. Enter “cmd” and click ok button.
  • 25.  Know we can run it. Thus we execute the program.

×