网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>JAVA>>新手入门>>基础入门>查看文档  
  用java编写的记事本程序(2)     
  文章作者:未知  文章来源:水木森林  
  查看:283次  录入:管理员--2007-11-17  
 
  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
 
 
上一篇: 用java编写的记事本程序(1)    下一篇: 用java编写的记事本程序(3)
  相关文档
如何使用eclipseme开发j2me程序 11-17
java编译、反编译、反反编译 11-17
小议如何在applet中显示图象 11-17
表现层框架struts/tapestry/jsf架构比较 01-30
ejb的困惑:组件与可重用性的矛盾 11-17
新手入门:初学者搭建j2me移动开发平台 11-16
我为什么学习hibernate 11-17
j2ee综合:struts上传多个文件的例子 01-07
为java应用程序添加退出事件响应 11-16
jsr 198最终草案提交 统一ide插件标准 11-17
sun公司推java认证取得成功 11-17
progressmonitorinputstream类的使用(笔记) 11-17
j2ee程序员应该掌握的linux系统的知识 11-16
servlet开发初步 11-17
图解 visual studio .net 团队开发 11-17
jsp如何与ejb sessionbean通讯 11-17
开发j2ee应用的要领 11-16
一篇介绍 java socket 编程的经典文章 11-16
进阶教程——java性能优化通用篇 11-17
在eclipse中构建备忘单 11-17
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
技术电话:13616026886
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息