王朝网络
分享
 
 
 

用Java编写的记事本程序(2)

王朝java/jsp·作者佚名  2008-05-31
宽屏版  字体: |||超大  

public void frame_windowclose_windowClosing(WindowListener e){

this.close();

}

/////////////////////////////////////////////////////////

public void text_mouseClicked(MouseEvent e){

if(e.getModifiers()==InputEvent.BUTTON3_MASK){

pop.show((Component)e.getSource(),e.getX(),e.getY());

}

}

public void text_ancestorAdded(AncestorEvent e){

this.dirty=false;

this.newtext();

}

public void text_caretUpdate(CaretEvent e)

{

this.dirty=true;

//this.statubar.setText(this.text.getText());

}

///////////// File /////////////////////////////////////

public void File_open_actionPerformed(ActionEvent e){

//打开的事件

this.opentext();

}

public void File_new_actionPerformed(ActionEvent e){

///新建的事件

this.newtext();

}

public void File_save_actionPerformed(ActionEvent e){

//保存的事件

this.save();

}

public void File_saveas_actionPerformed(ActionEvent e){

//另存为

this.saveas();

}

public void File_quite_actionPerformed(ActionEvent e){

this.close();

}

////////////////// Edit /////////////////////////////////////

public void Edit_undo_actionPerformed(ActionEvent e){

//撤销

this.undo();

}

public void Edit_cut_actionPerformed(ActionEvent e){

//剪切

this.cut();

}

public void Edit_copy_actionPerformed(ActionEvent e){

//复制

this.copy();

}

public void Edit_paste_actionPerformed(ActionEvent e){

//粘贴

this.paste();

}

public void Edit_delete_actionPerformed(ActionEvent e){

//删除

this.delete();

}

public void Edit_find_actionPerformed(ActionEvent e){

//查找

int cu=this.text.getCaretPosition();

int end=this.text.getText().length();

FindDlg fd=new FindDlg(frame,"查找",true);

fd.show();

String str=fd.getFindStr().trim();

if(fd.getFlag()){

this.nextFindStr(str,cu,end);

}else{

this.upFindStr(str,cu);

}

}

public void Edit_replace_actionPerformed(ActionEvent e){

//替换

int cu=this.text.getCaretPosition();

int end=this.text.getText().length();

ReplaceDlg rd=new ReplaceDlg(frame,"替换",true);

rd.show();

this.replaceStr(rd.findStr().trim(),rd.replaceStr().trim(),cu,end);

}

public void Edit_selectall_actionPerformed(ActionEvent e){

//全选

this.text.setSelectionStart(0);

this.text.setSelectionEnd(this.text.getText().length());

}

public void Edit_timedate_actionPerformed(ActionEvent e){

//时间日期

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

this.text.append("\r\n当前时间:"+sdf.format(new Date()));

}

///////////// Format//////////////////////////////////////

public void Format_Word_actionPerformed(ActionEvent e){

//自动换行

if(!this.text.getLineWrap()){

this.text.setLineWrap(true);

}

else{

this.text.setLineWrap(false);

}

}

public void Format_font_actionPerformed(ActionEvent e){

//字体"常规","斜体","粗体","粗斜体"

Font cur=this.text.getFont();

int type=Font.BOLD;

FontSet fs=new FontSet(frame,"字体设置",true);

fs.show();

if(fs.flag){

switch(fs.font2()){

case 0:type=Font.PLAIN;break;

case 1:type=Font.99vALIC;break;

case 2:type=Font.BOLD; break;

case 3:type=Font.ROMAN_BASELINE;break;

default:type=Font.PLAIN;break;

}

Font f=new Font(fs.font1(),type,16);

this.text.setFont(f);

}else{

this.text.setFont(cur);

}

}

public void Format_color_actionPerformed(ActionEvent e){

// 颜色

Color current=this.text.getForeground();

this.jColor.setColor(current);

this.text.setForeground(

this.jColor.showDialog(text,"选择颜色",current));

}

//////////////////// Help /////////////////////////////////////

public void Help_about_actionPerformed(ActionEvent e){

//关于作者

new AboutDlg();

}

////////////////////////////////////////////////////////

public void pop_undo_actionPerformed(ActionEvent e){

//Pop undo

this.undo();

}

public void pop_cut_actionPerformed(ActionEvent e){

//pop cut

this.cut();

}

public void pop_copy_acionPerformed(ActionEvent e){

//pop copy

this.copy();

}

public void pop_paste_actionPerformed(ActionEvent e){

//pop paste

this.paste();

}

public void pop_delete_actionPerformed(ActionEvent e){

//pop delete

this.delete();

}

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

/////////////////////////////////////////////////////////////

////////////// coustm function ///////////////////////////////

/////////////////////////////////////////////////////////////

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

void close(){

if(this.dirty){

Dlgtext Dt=new Dlgtext(frame,"提示",true);

Dt.show();

if(Dt.getCheck()){

this.save();

}

else {

frame.dispose();

System.exit(0);

}

}else{

frame.dispose();

System.exit(0);

}

}

void newtext(){//新建

if((!this.dirty)(!this.saveas())){

this.text.setText("");

this.text.setFocusable(true);

this.frame.setTitle("未命名-----Author:Jeason");

this.statubar.setText("新建文本");

}

else this.saveas();

}

void opentext(){//打开

//

String strFileOpen="";

if(!this.dirty){

try{

if(this.jFileChooser1.APPROVE_OPTION==

this.jFileChooser1.showOpenDialog(frame)){

strFileOpen=this.jFileChooser1.getSelectedFile().getPath();

File file=new File(strFileOpen);

int flength=(int)file.length();

int num=0;

FileReader fReader=new FileReader(file);

char[] data=new char[flength];

while(fReader.ready()){

num+=fReader.read(data,num,flength-num);

}

fReader.close();

this.text.setText(new String(data,0,num));

this.filename=strFileOpen;

this.frame.setTitle(this.filename);

this.statubar.setText("Open File:"+this.filename);

this.dirty=false;

}else

{

return ;

}

}catch(Exception e){

this.statubar.setText("Error Open:"+e.getMessage());

}

}else{

this.save();

}

}

boolean save(){//保存

if(this.dirty){

if(this.filename.length()!=0){

try{

File saveFile=new File(this.filename);

FileWriter fw=new FileWriter(saveFile);

fw.write(this.text.getText());

fw.close();

this.dirty=false;

this.statubar.setText("保存文件:"+this.filename);

return true;

}catch(Exception e)

{

this.statubar.setText("保存出错: "+e.getMessage());

return false;

}

}else{

return this.saveas();

}

}else{

return true;

}

}

boolean saveas(){//另存为

if(this.jFileChooser1.APPROVE_OPTION==this.jFileChooser1.showSaveDialog(frame)){

this.filename=this.jFileChooser1.getSelectedFile().g

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有