My JCreator - version 1 built1

7 views
Skip to first unread message

uit...@yahoo.com

unread,
Aug 6, 2006, 10:17:26 AM8/6/06
to Open Projects For All
/*Following is a program to emulate JCreator
This program currently suports save, but compilation is not working*/

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;


class MyJCreator extends JFrame
{


Process p =null; // used for executing javac

JMenuBar topBar ;
JMenu menuFile , menuEdit , menuHelp ;
JMenuItem itmNew , itmOpen , itmSave , itmClose , itmCopy , itmCut ,
itmPaste , itmAbout ;
JTextArea tAreaEditor ;
JFileChooser myFileChooser , mySaveFile ;
Container c ;
String savedFileName;


JButton buttonCompile , buttonRun ;
MyJCreator ()
{
super("My Notepad ");
c = getContentPane();
c.setLayout(new BorderLayout());

//adding the text editor

tAreaEditor = new JTextArea (20,40);
tAreaEditor .setLineWrap(true) ;

//creating the button for compilation and running
buttonCompile = new JButton("Compile");
buttonRun = new JButton("Run");


//creates the new file chooser
myFileChooser = new JFileChooser();
mySaveFile = new JFileChooser();

topBar = new JMenuBar ();

// adding contents for the menu --> file

menuFile = new JMenu ("File");

itmNew = new JMenuItem ("New");
itmOpen = new JMenuItem ("Open");
itmSave = new JMenuItem ("Save");
itmClose = new JMenuItem ("Close");


menuFile .add(itmNew );
menuFile .add(itmOpen );
menuFile .add( itmSave );
menuFile .add(itmClose );


topBar .add(menuFile );
//*********************************************

// adding contents for the menu --> Edit

menuEdit = new JMenu ("Edit");
itmCut = new JMenuItem ("Cut");
itmCopy = new JMenuItem ("Copy");
itmPaste = new JMenuItem ("Paste");

menuEdit .add(itmCut );
menuEdit .add(itmCopy );
menuEdit .add(itmPaste );

topBar .add(menuEdit );

//*********************************************

menuHelp = new JMenu ("Help");
itmAbout = new JMenuItem ("About");

menuHelp .add(itmAbout );
topBar .add(menuHelp );


//*********************************************

//ADDING ACTION LISTENERS FOR THE MENU
//--------------------------------------------------------------------
MyMenuListener mm1 =new MyMenuListener ();

itmNew .addActionListener(mm1);
itmSave .addActionListener(mm1);

itmOpen .addActionListener(mm1);

// edit listeners

itmCut.addActionListener(mm1);
itmPaste.addActionListener(mm1);
itmCopy.addActionListener(mm1);

// Help listeners

itmAbout.addActionListener(mm1);

//ADDING ACTION LISTENERS FOR THE 2 BUTTONS
//--------------------------------------------------------------------


MyButtonListener butLisn =new MyButtonListener ();
buttonCompile .addActionListener(butLisn );
buttonRun .addActionListener(butLisn );

setJMenuBar(topBar);

//___________________________________________________
JToolBar togglePanel = new JToolBar();

//also add the button for compilation and running
togglePanel .add(buttonCompile);
togglePanel .add(buttonRun );

c.add(togglePanel ,BorderLayout.NORTH);
//_________________________________________________


JScrollPane myScrollPane = new JScrollPane(tAreaEditor );


c.add( myScrollPane);

}

//LISTENERS FOR COMPILATION AND RUNNING

private class MyButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{

if(e.getSource() == buttonCompile )
{
Runtime r = Runtime.getRuntime();
r.traceInstructions(true);
try
{
p =r.exec("D:\\j2sdk1.4.2_08\\bin\\javac "+savedFileName );
// D:\j2sdk1.4.2_08\bin\javac OpeningIETest.java
//p =r.exec("C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE
");
// InputStream is = p.getErrorStream();
// byte[] b = new byte[is.available()];
// System.out.println(is.available());
// is.read(b);
// String s = new String(b);
// if(s != null){
// System.out.println("Error:"+s);
// }
}
catch(Exception ex)
{
}

}//end of if condition


if(e.getSource() == buttonRun )
{
Runtime r = Runtime.getRuntime();
try
{
p =r.exec("D:\\j2sdk1.4.2_08\\bin\\java "+savedFileName );
}
catch(Exception ex)
{
}
}//end of if condition

} //end of actionPerformed
} // end of inner class


private class MyMenuListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{

if( e.getSource() == itmNew )
tAreaEditor.setText("");

if( e.getSource() == itmOpen )
myFileChooser.showOpenDialog(c) ;

if( e.getSource() == itmSave)
{
PrintWriter pw;
FileOutputStream outputfile;

mySaveFile .showSaveDialog(c) ;
File f =mySaveFile .getSelectedFile() ;


savedFileName = f.getPath() ;

System.out.println("The path of the file is: "+ savedFileName );
try {

outputfile = new FileOutputStream( savedFileName );
//
byte data[] =tAreaEditor .getText().getBytes();
outputfile.write(data);

}

catch(Exception excp)
{
System.out.println("get the hell out of here");
}

}


if( e.getSource() == itmCut )
tAreaEditor.cut();

if( e.getSource() == itmCopy )
tAreaEditor.copy();

if( e.getSource() == itmPaste )
tAreaEditor.paste();


if( e.getSource() == itmAbout )
JOptionPane.showMessageDialog(null, "name: Justin"+
"\n\nLicense:GNU GPL"+
"\n\ne-mail: just...@gmail.com");

}
}

}
class MyJCreatorTest
{
public static void main(String args[])
{
MyJCreator m1 = new MyJCreator ();
m1.setSize(480,400);
m1.setVisible(true);
m1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}


//*********************************************

uit...@yahoo.com

unread,
Aug 12, 2006, 8:18:00 AM8/12/06
to Open Projects For All
//current additions
//error messge gets displayed in the prompt


//future enhancements : use of textpane
// the error is stored in the line variable, use it to display in a
JDialog box


class MyJCreator extends JFrame
{

//adding the text editor


topBar .add(menuFile );
//*********************************************

topBar .add(menuEdit );

//*********************************************


//*********************************************

itmNew .addActionListener(mm1);
itmSave .addActionListener(mm1);

itmOpen .addActionListener(mm1);

// edit listeners

itmCut.addActionListener(mm1);
itmPaste.addActionListener(mm1);
itmCopy.addActionListener(mm1);

// Help listeners

itmAbout.addActionListener(mm1);

setJMenuBar(topBar);

c.add(togglePanel ,BorderLayout.NORTH);
//_________________________________________________


c.add( myScrollPane);

}

if(e.getSource() == buttonCompile )
{
//Runtime r = Runtime.getRuntime();
//r.traceInstructions(true);
try
{
System.out.println("Ahsha v nair varathhille ? office
paranchitunde");

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("javac OpeningIETest.java");
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("<ERROR>");
while ( (line = br.readLine()) != null)
System.out.println(line);
System.out.println("</ERROR>");
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
JOptionPane.showMessageDialog(null,line);
}

//p =r.exec("D:\\j2sdk1.4.2_08\\bin\\javac OpeningIETest.java" );


catch(Exception ex)
{
}

}//end of if condition


if(e.getSource() == buttonRun )
{
Runtime r = Runtime.getRuntime();
try
{

p =r.exec("D:\\j2sdk1.4.2_08\\bin\\java OpeningIETest.java" );

Reply all
Reply to author
Forward
0 new messages