Ex11 mini project

29
Elanthendral.M (HDCA) Elanthendral.M (HDCA) 11.Develop a programmer’s editor in java that 11.Develop a programmer’s editor in java that supports syntaxhighlighting, compilation supports syntaxhighlighting, compilation support ,debugging support,ect… support ,debugging support,ect… Aim Aim :- To Develop a programmer’s editor in java that supports Syntax Highlighting , compilation support , Debugging support. Algorithm:- Algorithm:- Syntax Highlighting Syntax Highlighting 1.1 Definition 1.1 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 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.

Transcript of Ex11 mini project

Page 1: Ex11 mini project

Elanthendral.M (HDCA)Elanthendral.M (HDCA)

11.Develop a programmer’s editor in java that supports11.Develop a programmer’s editor in java that supports syntaxhighlighting, compilation support ,debugging support,ect…syntaxhighlighting, compilation support ,debugging support,ect…

AimAim   :- To Develop a programmer’s editor in java that supports Syntax Highlighting ,

compilation support , Debugging support.

Algorithm:-Algorithm:-

II Syntax HighlightingSyntax Highlighting

1.1 Definition1.1 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 IntroductionIntroduction::-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 Procedure1.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?

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.

Page 2: Ex11 mini project

iii. Any other simple way that doesn’t involve using something other than JTextArea.

IIII Compilation Compilation

2. 1 Definition2. 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 compilation2.2Java compilationi. 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.3 Introduction:- 2.4Two main parts the compilation2.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 a flow of sounds

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.

Page 3: Ex11 mini project

III Debugging :-III Debugging :-

3. Definition3. 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 TipsIV Tool Tips :-

i. Creating a tool tip for any Jcomponent object is easy .use the setToolTipText method to set up a tool tip for the component .

ii. In this program we use the this type of the ToolTip;

V TaskV Task ManagerManager In this project we use task

manager

5.1 how to get the running applications in windows task manager using 5.1 how to get the running applications in windows task manager using javajava

Picture Picture name Tooltip name

NEW new.gifOpen open.gifSave save.gifCopy copy.gifCut cut.gif

Past past.gif

Page 4: Ex11 mini project

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 TaskManager

5.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.

ii. You can use Task Manager to monitor key indicators of your computer's 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 runningPrograms 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 5.4 Processes that are runningProcesses that are running

Page 5: Ex11 mini project

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 measuresPerformance measures

The Performance tab displays a dynamic overview of your computer's 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 5.6 Viewing Network performanceViewing 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.

5.75.7Monitoring SessionsMonitoring 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.

ProgramProgram :-:-

import java.awt.*;import java.awt.event.*;

Page 6: Ex11 mini project

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 field

JToolBar tb = new JToolBar();

// icf & b1 an array of values.

String icf[] = {"new.gif","open.gif","save.gif","cut.gif","copy.gif","paste.gif"};

// b1 represents for Tooltip

String bl[] = {"New","Open","Save","Cut","Copy","Paste"};

// Demonstrate a one-dimensional array

ImageIcon ic[] = new ImageIcon[icf.length];

// use a lable to display syntax highlighting

Label l1 = new Label("Syntax Highlighting");JButton mbl[] = new JButton[icf.length];

// set up manu bar

MenuBar mbar = new MenuBar();Menu a = new Menu("File");

Page 7: Ex11 mini project

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 the Value 13JTextArea ta,ta1;JScrollPane js1;

// create a fontList using GraphicsEnvironment

String fontList[] =GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

// create MenuItem

MenuItem 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");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);

Page 8: Ex11 mini project

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

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 MenuItem

for (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

Page 9: Ex11 mini project

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); 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());

Page 10: Ex11 mini project

// This Listener can be performed in this object

a1.addActionListener(this);a2.addActionListener(this);a3.addActionListener(this);a4.addActionListener(this);

// This Listener can be performed in wc object

a5.addActionListener(new wc());b1.addActionListener(new wc());b2.addActionListener(new wc());b3.addActionListener(new wc());d1.addActionListener(new wc());d2.addActionListener(new wc());ta.addKeyListener(this);

show();}

//set button action

public class wh extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0);}}

// an ActionListener that sets the FontSize

public class fs implements ActionListener { public void actionPerformed(ActionEvent e) {fsize = Integer.parseInt(e.getActionCommand()); System.out.println(fsize);}}

public class wc implements ActionListener {

Page 11: Ex11 mini project

public void actionPerformed(ActionEvent e) {

// create button actions

String cmd= e.getActionCommand();

// associate actions with buttons

if (cmd.equals("Exit")) System.exit(0);if (cmd.equals("Cut")) ta.cut();if (cmd.equals("Copy")) ta.copy();if (cmd.equals("Paste")) ta.paste();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;

Page 12: Ex11 mini project

// 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=""; }

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("else\n"); ta1.append("{\n"); ta1.append(" set of statements;\n"); ta1.append("}\n"); ck = ""; }

if (ck.equals("do ")) { ta1.setText(""); ta1.append("do\n"); 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");

Page 13: Ex11 mini project

ta1.append("}\n"); ck = ""; }

if (mk == 10 || mk == 32 || mk == 8 || mk == 9) ck =""; }

//to create Button Link

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

Page 14: Ex11 mini project

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){}; 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);

Page 15: Ex11 mini project

fos.close(); } catch(Exception e){}; ck1=0; }

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){};

}

Page 16: Ex11 mini project

if (s1.equals("New")) { ta.setText("");}

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();}}

Page 17: Ex11 mini project

Out put:-Out put:-

The output layout The output layout

The file menu out put:-The file menu out put:-

Page 18: Ex11 mini project

In this file menu we can do the following performances. there are:-i. Create a New file

ii. Open a fileiii. Save a fileiv. Save as a filev. Exit

Performances for the file menuPerformances 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.

Page 19: Ex11 mini project

I.I. Save a fileSave a file

On the File menu, click Save. In the File name box, enter a new name for the file. Click Save.

Saveas a fileSaveas a file1. 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 IdemThere are:-

i. Cutii. Copy

iii. Paste

Page 20: Ex11 mini project

II.II. Copy a fileCopy 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 THE FOLLOWING 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.

Page 21: Ex11 mini project

The out put for system

Procedure for compilation:- First write a program. Then click systemcompile.

Page 22: Ex11 mini project

The Task Manager Dialog box can be opened. Then click filecompile.

Task Manager dialog box can be apper.

Page 23: Ex11 mini project

Then go to file menu in the Task Manager.

Select NEW TASK(RUN…) ,then Run dialog box can be apper.

Page 24: Ex11 mini project

Enter “cmd” and click ok button.

Know we can run it.

Thus we execute the program.