Professional Documents
Culture Documents
MenuItem item1,item2,item3,item4,item5,item6; MenuItem item7,item8,item9; MenuItem item10; MenuItem fontitem1,fontitem2,fontitem3,fontitem4; MenuItem sizeitem1,sizeitem2,sizeitem3,sizeitem4,sizeitem5,sizeitem6,sizeitem7, sizeitem8,sizeitem9,sizeitem10,sizeitem11,sizeitem12; MenuItem styleitem1,styleitem2,styleitem3; MenuItem bkcitem[]=new MenuItem[13];
int fontNumeric=12;
FileDialog openDialog; FileDialog saveDialog; private ErrorDialog errorDialog=null; private TEDialog teDialog=null;
String s; static String st=""; String heading =" Save File ";
super(title);
setMenuBar(mbar);
menu(mbar);
//create an object to handle window events MyWindowAdapter adapter=new MyWindowAdapter(this); //register it to receive those event addWindowListener(adapter);
//addKeyListener(this); //requestFocus();
public void menu1(MenuBar mbar){//start of menu1() Menu help = new Menu(" Help "); help.add(item10 = new MenuItem("About..")); mbar.add(help); item10.addActionListener(this);
file.add(item1=new MenuItem("New")); file.add(item2=new MenuItem("Open")); file.add(item3=new MenuItem("Close")); file.add(item4=new MenuItem("Save")); file.add(item5=new MenuItem("Save As")); file.addSeparator(); file.add(item6=new MenuItem("Exit"));
mbar.add(file);
edit.add(item7=new MenuItem("Cut"));
mbar.add(edit);
mbar.add(font);
size.add(sizeitem12=new MenuItem("30"));
mbar.add(size);
mbar.add(fontstyle);
sizeitem1.addActionListener(this); sizeitem2.addActionListener(this); sizeitem3.addActionListener(this); sizeitem4.addActionListener(this); sizeitem5.addActionListener(this); sizeitem6.addActionListener(this); sizeitem7.addActionListener(this); sizeitem8.addActionListener(this); sizeitem9.addActionListener(this); sizeitem10.addActionListener(this);
sizeitem11.addActionListener(this); sizeitem12.addActionListener(this);
Menu bkcolor=new Menu(" BackGround Color "); Menu frcolor=new Menu(" Text Color ");
String frcolname[]={" Red"," Blue"," Green"," Cyan"," Black"," Dark Gray", " Gray"," Light Gray"," Magenta"," Orange"," Pink"," White" ," Yellow"};
for(int i=0;i<=12;i++)
} mbar.add(bkcolor); mbar.add(frcolor);
tx1.setEditable(true); fc1.add(tx1);
/////////////////////////////////////////////////////////////////////////////
String args=(String)ae.getActionCommand(); if(args.equals("New")) { StartNewWindow(); } else if(args.equals("Open")){heading=" Save File ";openFile();} else if(args.equals("Save")){heading=" Save File ";saveOpenedFile();} else if(args.equals("Close")){closedFile();} else if(args.equals("Save As")){heading=" Save File As ";saveAsFile(this);} else if(args.equals("Exit")){System.exit(0);} else if(args.equals("Cut")){cut();} else if(args.equals("Copy")){copy();} else if(args.equals("Paste")){paste();} else if(args.equals("Courier")){fontName="Courier";textfont();} else if(args.equals("Arial")){fontName="Arial";textfont();} else if(args.equals("TimesRoman")){fontName="TimesRoman";textfont();} else if(args.equals("8")){fontNumeric=8;textfont();} else if(args.equals("8")){fontNumeric=8;textfont();} else if(args.equals("8")){fontNumeric=8;textfont();} else if(args.equals("10")){fontNumeric=10;textfont();} else if(args.equals("12")){fontNumeric=12;textfont();}
else if(args.equals("14")){fontNumeric=14;textfont();} else if(args.equals("16")){fontNumeric=16;textfont();} else if(args.equals("18")){fontNumeric=18;textfont();} else if(args.equals("20")){fontNumeric=20;textfont();} else if(args.equals("22")){fontNumeric=22;textfont();} else if(args.equals("24")){fontNumeric=24;textfont();} else if(args.equals("26")){fontNumeric=26;textfont();} else if(args.equals("28")){fontNumeric=28;textfont();} else if(args.equals("30")){fontNumeric=30;textfont();} else if(args.equals("Bold")){fontStyle=Font.BOLD;textfont();} else if(args.equals("Plain")){fontStyle=Font.PLAIN;textfont();} else if(args.equals("Italic")){fontStyle=Font.ITALIC;textfont();}
else if(args.equals("Red")){tx1.setBackground(Color.red);} else if(args.equals("Blue")){tx1.setBackground(Color.blue);} else if(args.equals("Green")){tx1.setBackground(Color.green);} else if(args.equals("Cyan")){tx1.setBackground(Color.cyan);} else if(args.equals("Black")){tx1.setBackground(Color.black);} else if(args.equals("Dark Gray")){tx1.setBackground(Color.darkGray);} else if(args.equals("Gray")){tx1.setBackground(Color.gray);} else if(args.equals("Light Gray")){tx1.setBackground(Color.lightGray);} else if(args.equals("Magenta")){tx1.setBackground(Color.magenta);} else if(args.equals("Orange")){tx1.setBackground(Color.orange);} else if(args.equals("Pink")){tx1.setBackground(Color.pink);} else if(args.equals("White")){tx1.setBackground(Color.white);}
else if(args.equals("Yellow")){tx1.setBackground(Color.yellow);} else if(args.equals(" Red")){tx1.setForeground(Color.red);} else if(args.equals(" Blue")){tx1.setForeground(Color.blue);} else if(args.equals(" Green")){tx1.setForeground(Color.green);} else if(args.equals(" Cyan")){tx1.setForeground(Color.cyan);} else if(args.equals(" Black")){tx1.setForeground(Color.black);} else if(args.equals(" Dark Gray")){tx1.setForeground(Color.darkGray);} else if(args.equals(" Gray")){tx1.setForeground(Color.gray);} else if(args.equals(" Light Gray")){tx1.setForeground(Color.lightGray);} else if(args.equals(" Magenta")){tx1.setForeground(Color.magenta);} else if(args.equals(" Orange")){tx1.setForeground(Color.orange);} else if(args.equals(" Pink")){tx1.setForeground(Color.pink);} else if(args.equals(" White")){tx1.setForeground(Color.white);} else if(args.equals(" Yellow")){tx1.setForeground(Color.yellow);} else if(args.equals("About..")){showTEDialog("I, Anuj Agrawal, am a student of Sikkim Manipal Istitute Of Technology, Sikkim.\n" +"This Text Editor was developed out of my pure interest in Java.\n" +"To know more about me or to get more of my projects pease visit\n\n"
+"http://anuj.page.tl\n" +"or\n"
+"http://anuj.ajad.googlepages.com\n" +"or\n"
+"http://www.anujag.tk\n"
+"or\n"
+"http://www.anujfrens.tk\n\n"
+"\tAnuj Agrawal");}
} // }
tx1.setFont(new Font(fontName,fontStyle,fontNumeric));
++window_counter; ++window_no;
st=Integer.toString(window_no);
Frame_class f=new Frame_class("<< Text Editor 1.0>> By << Anuj Agrawal >> : New Window "+st);
f.setSize(700,600); }
if(lentest()){ saveOpenedFile(); newWindow();String ar; if(window_no>=1){ar="New Window "+st+" : ";}else ar=""; this.setTitle("<< Text Editor 1.0>> By << Anuj Agrawal >> : "+ar+"*.*");
} else newWindow();}
int key=ke.getKeyCode();
}*/ ////////////////////////////////////////////////////////////////////////////////
// The Dialog boxes for openinig and saving file private void AddDialog(){
copystring=tx1.getSelectedText(); tx1.requestFocus(); }
openDialog.setVisible(true);
filename=openDialog.getFile(); if(filename!=null){ filename=check(filename); if(read(filename)) { fileName=filename;String ar; if(window_no>=1){ar="New Window "+st+" : ";}else ar=""; this.setTitle("<< Text Editor 1.0>> By << Anuj Agrawal >> : "+ar+fileName); } } tx1.requestFocus(); }
String line; FileInputStream in = null; DataInputStream dataIn =null; BufferedInputStream bis=null; StringBuffer buffer=new StringBuffer();
try{ in =new FileInputStream(filename); bis=new BufferedInputStream(in); dataIn=new DataInputStream(bis); } catch(Throwable e){ showErrorDialog("Can't open\""+filename+"\""); return (false); }
in.close(); tx1.setText(buffer.toString());
//method saves a file you opened previously //method produces error if you did not open a file previously
if(!lentest()) showErrorDialog("There is no <<Text>> to Save");else if(fileName==null) { saveAsFile(this); //showErrorDialog("You did not previously open a file.Use save as."); } else { write(fileName);
tx1.requestFocus(); } }
//methods save as the file you are currently editing private void saveAsFile(Frame_class f1){ if(!lentest()) showErrorDialog("There is no <<Text>> to Save");else { String filename; saveDialog.setVisible(true); filename=saveDialog.getFile();
if(filename!=null){ filename=check(filename); if(write(filename)) { fileName=filename; f1.setTitle("<< Text Editor 1.0>> By << Anuj Agrawal >> : "+heading+" : "+fileName+" "+st);
} }
tx1.requestFocus(); }
//method handles writing files to the file system private boolean write (String filename){
FileOutputStream os=null;
try{
try{
//DialogBoxes....... public void showErrorDialog(String message){ if(errorDialog!=null)errorDialog.dispose(); errorDialog=new ErrorDialog(this,message); errorDialog.setVisible(true); } public void showTEDialog(String message){ if(teDialog!=null)teDialog.dispose(); teDialog=new TEDialog(this,message); teDialog.setVisible(true); } }//close brace of Frame_class
//////////////////////////////////////////////////////////////////////////////// class ErrorDialog extends Dialog{ Frame_class parent; String message; public ErrorDialog(Frame_class parent,String message){ super(parent,"Error",true); setBackground(Color.yellow); this.parent=parent; this.message=message;
Panel p;
switch(event.id){ case Event.WINDOW_DESTROY: dispose(); parent.tx1.requestFocus(); return(true); } return(false); } } class TEDialog extends Dialog{ Frame_class parent; String message; public TEDialog(Frame_class parent,String message){ super(parent,"TextEditor 1.0",true); setBackground(Color.yellow); this.parent=parent; this.message=message;
TextArea p;
Frame f1=new Frame_class("<< Text Editor 1.0>> By << Anuj Agrawal >>"); //f1.setVisible(true);
/////////////////////////////////////////////////////////////////////////////////