网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>JAVA>>新手入门>>基础入门>查看文档  
  用java编写的记事本程序     
  文章作者:未知  文章来源:水木森林  
  查看:100次  录入:管理员--2007-11-17  
 
  这个学期,我们学习了java编程,期末之时老师要我们编个记事本作为这门课程的课程设计,我写了一个,大体上的功能都实现了,只有"撤销"的功能没有实现,请各位大虾指点一下,“撤销”的算法,不甚感激!
特将记事本的源码附下,请大家指点,看还有没有更简洁高效的算法,请不要吝啬,我的e-mail:yangyong@ccsu.cn,欢迎大家来信指点!

/*
*
*题目:记事本程序
*author: jeason
*
* 2004-12-20
*
**/
package jeason;

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

public class jsb{

///
boolean dirty=true;
string filename="";
string strtext="";


///////////////////////////////////
////////// menu ////////////////
///////////////////////

jframe frame=new jframe("我的记事本");
jpopupmenu pop=new jpopupmenu("弹出");
jtextarea text=new jtextarea();
jlabel statubar=new jlabel("状态栏");
jmenubar mbar=new jmenubar();
jfilechooser jfilechooser1=new jfilechooser();

jcolorchooser jcolor=new jcolorchooser();

jmenu jfile=new jmenu("文件");
jmenu jedit=new jmenu("编辑");
jmenu jformat=new jmenu("格式");
jmenu jhelp=new jmenu("帮助");

jmenuitem jnew=new jmenuitem("新建(n)");

public jsb(){ ///无参数的构造函数

///
this.dirty=false;
/////



final borderlayout borderlayout1=new borderlayout();

frame.setsize(600,500);//
frame.addwindowlistener(new jsb_frame_closingadapter(this));

jpanel panel=new jpanel();
panel.setlayout(borderlayout1);//布局
panel.add(new jscrollpane(text));//滚动条
panel.add(statubar,borderlayout1.south);


frame.getcontentpane().add(panel);
//
frame.setjmenubar(mbar); //将主菜单添加到窗体中





/*
* jnew
**/
//jnew
jnew.addactionlistener(new file_new_actionadapter(this));
jnew.setmnemonic(´n´);//n上下划线
jnew.setaccelerator(keystroke.getkeystroke(´n´,java.awt.event.ctrl_mask,true));
//快捷方式


/*
* jopen
**/
jmenuitem jopen=new jmenuitem("打开(o)");//jopen
jopen.addactionlistener(new file_open_actionadapter(this));
jopen.setmnemonic(´o´);
jopen.setaccelerator(keystroke.getkeystroke(´o´,java.awt.event.ctrl_mask,true));

/*
* jsave
**/
jmenuitem jsave=new jmenuitem("保存(s)");
jsave.addactionlistener(new file_save_actionadapter(this));
jsave.setmnemonic(´s´);
jsave.setaccelerator(keystroke.getkeystroke(´s´,java.awt.event.ctrl_mask,true));


/*
* jsave as
**/
jmenuitem jsaveas=new jmenuitem("另存为...");
jsaveas.addactionlistener(new file_saveas_actionadapter(this));
/*
* jquite
**/

jmenuitem jquite=new jmenuitem("关闭(q)");
jquite.addactionlistener(new file_quite_actionadapter(this));
jquite.setmnemonic(´q´);
jquite.setaccelerator(keystroke.getkeystroke(´q´,java.awt.event.ctrl_mask,true));



//------------------------------------
// jfile code of end
//--------------------------------------

/**
* jedit code
*/
//jundo
jmenuitem jundo=new jmenuitem("撤销(u)");
jundo.addactionlistener(new edit_undo_actionadapter(this));
jundo.setmnemonic(´u´);
jundo.setaccelerator(keystroke.getkeystroke(´u´,java.awt.event.ctrl_mask,true));

/*
* jcut
**/
jmenuitem jcut=new jmenuitem("剪切(x)");
jcut.addactionlistener(new edit_cut_actionadapter(this));
jcut.setmnemonic(´x´);
jcut.setaccelerator(keystroke.getkeystroke(´x´,java.awt.event.ctrl_mask,true));

/*
* jcopy
**/
jmenuitem jcopy=new jmenuitem("复制(c)");
jcopy.addactionlistener(new edit_copy_actionadapter(this));
jcopy.setmnemonic(´c´);
jcopy.setaccelerator(keystroke.getkeystroke(´c´,java.awt.event.ctrl_mask,true));

/*
* jpaste
**/
jmenuitem jpaste=new jmenuitem("粘贴(v)");
jpaste.addactionlistener(new edit_paste_actionadapter(this));
jpaste.setmnemonic(´v´);
jpaste.setaccelerator(keystroke.getkeystroke(´v´,java.awt.event.ctrl_mask,true));

/*
* jdelete
**/
jmenuitem jdelete=new jmenuitem("删除(d)");
jdelete.addactionlistener(new edit_delete_actionadapter(this));
jdelete.setmnemonic(´d´);
jdelete.setaccelerator(keystroke.getkeystroke(´d´,java.awt.event.ctrl_mask,true));

/*
* jfind
**/
jmenuitem jfind=new jmenuitem("查找(f)");
jfind.addactionlistener(new edit_find_actionadapter(this));
jfind.setmnemonic(´f´);
jfind.setaccelerator(keystroke.getkeystroke(´f´,java.awt.event.ctrl_mask,true));

/*
* jreplace
**/
jmenuitem jreplace=new jmenuitem("替换(r)");
jreplace.addactionlistener(new edit_replace_actionadapter(this));
jreplace.setmnemonic(´r´);
jreplace.setaccelerator(keystroke.getkeystroke(´r´,java.awt.event.ctrl_mask,true));

/*
*jselectall
**/
jmenuitem jselectall=new jmenuitem("全选(a)");
jselectall.addactionlistener(new edit_selectall_actionadapter(this));
jselectall.setmnemonic(´a´);
jselectall.setaccelerator(keystroke.getkeystroke(´a´,java.awt.event.ctrl_mask,true));

/*
* jdate
**/
jmenuitem jdate=new jmenuitem("日期/时间(t)");
jdate.addactionlistener(new edit_timedate_actionadapter(this));
jdate.setmnemonic(´t´);
jdate.setaccelerator(keystroke.getkeystroke(´t´,java.awt.event.ctrl_mask,true));




//------------------------------
// jedit code of end
//
//-----------------------------

/*
* jword
**/
jmenuitem jword=new jmenuitem("自动换行");
jword.addactionlistener(new format_word_actionadapter(this));

/*
* jfont
**/
jmenuitem jfont=new jmenuitem("字体..");
jfont.addactionlistener(new format_font_actionadapter(this));

/*
* jcolor
**/
jmenuitem jcolor=new jmenuitem("颜色...");
jcolor.addactionlistener(new format_color_actionadapter(this));



//--------------------------------------------------
// jformat code of end
//--------------------------------------------------

/*
* jabout
**/
jmenuitem jabout=new jmenuitem("关于作者(a)");
jabout.addactionlistener(new help_about_actionadapter(this));
jabout.setmnemonic(´a´);
jabout.setaccelerator(keystroke.getkeystroke(´a´,java.awt.event.ctrl_mask,true));



//-------------------------------------------------
// jhelp code of end
//------------------------------------------------------

/*************************************************
*------------------------------------------------
* popupmenuitem
*------------------------------------------------
*************************************************/
/*
* pundo
**/
jmenuitem pundo=new jmenuitem("撤销(u)");
pundo.addactionlistener(new pop_undo_actionadapter(this));
pundo.setmnemonic(´u´);
pundo.setaccelerator(keystroke.getkeystroke(´u´,java.awt.event.ctrl_mask,true));

/*
* pcut
**/
jmenuitem pcut=new jmenuitem("剪切(x)");
pcut.addactionlistener(new pop_cut_actionadapter(this));
pcut.setmnemonic(´x´);
pcut.setaccelerator(keystroke.getkeystroke(´x´,java.awt.event.ctrl_mask,true));

/*
* pcopy
**/
jmenuitem pcopy=new jmenuitem("复制(c)");
pcopy.addactionlistener(new pop_copy_actionadapter(this));
pcopy.setmnemonic(´c´);
pcopy.setaccelerator(keystroke.getkeystroke(´c´,java.awt.event.ctrl_mask,true));

/*
* ppaste
**/
jmenuitem ppaste=new jmenuitem("粘贴(v)");
ppaste.addactionlistener(new pop_paste_actionadapter(this));
ppaste.setmnemonic(´v´);
ppaste.setaccelerator(keystroke.getkeystroke(´v´,java.awt.event.ctrl_mask,true));

/*
*pdelete
**/
jmenuitem pdelete=new jmenuitem("删除(d)");
pdelete.addactionlistener(new pop_delete_actionadapter(this));
pdelete.setmnemonic(´d´);
pdelete.setaccelerator(keystroke.getkeystroke(´d´,java.awt.event.ctrl_mask,true));




////////
///////////// text////////////////////////////////////////
text.setdoublebuffered(false);
text.settooltiptext("杨勇的记事本");
text.setverifyinputwhenfocustarget(true);
text.settext("");

text.addcaretlistener(new jsb_text_caretadapter(this));
text.addmouselistener(new jsb_text_mouseadapter(this));
text.addancestorlistener(new jsb_text_ancestoradapter(this));

//////////////////////////////////////////////////////////
mbar.add(jfile);
mbar.add(jedit);
mbar.add(jformat);
mbar.add(jhelp);

jfile.add(jnew);
jfile.add(jopen);
jfile.addseparator();
jfile.add(jsave);
jfile.add(jsaveas);
jfile.addseparator();
jfile.add(jquite);

jedit.add(jundo);
jedit.addseparator();
jedit.add(jcut);
jedit.add(jcopy);
jedit.add(jpaste);
jedit.add(jdelete);
jedit.addseparator();
jedit.add(jfind);
jedit.add(jreplace);
jedit.addseparator();
jedit.add(jselectall);
jedit.add(jdate);

jformat.add(jword);
jformat.addseparator();
jformat.add(jfont);
jformat.addseparator();
jformat.add(jcolor);

jhelp.add(jabout);

pop.add(pundo);
pop.addseparator();
pop.add(pcut);
pop.add(pcopy);
pop.add(ppaste);
pop.add(pdelete);

frame.setvisible(true);



}
/************************************************************
//////////////////////event/////////////////////////////////
**************************************************************/

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("当前时间:"+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.italic;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().getpath();
return this.save();
}else{
return false;
}
}

void undo(){
//undo
}
void cut(){
//cut
try{
string str=this.text.getselectedtext();
if(str.length()!=0){
this.strtext=str;
this.text.replacerange("",this.text.getselectionstart(),this.text.getselectionend());
this.dirty=true;
}
}catch(exception ex){
this.statubar.settext("剪切出错:"+ex.getmessage());
}
}
void copy(){
//copy
try{
string str=this.text.getselectedtext();
if(str.length()!=0){
this.strtext=str;
}
}catch(exception ex)
{
this.statubar.settext("复制出错!"+ex.getmessage());
}
}
void paste(){
//paste
if(this.strtext.length()>0){
this.text.insert(this.strtext,this.text.getcaretposition());
this.dirty=true;
}
}
void delete(){
//delete
this.text.replacerange("",this.text.getselectionstart(),this.text.getselectionend());
this.dirty=true;
}

void nextfindstr(string str,int cur,int end){
if(cur>end){
this.statubar.settext("没有找到!");
}
else{
int i=this.text.gettext().indexof(str);
if(i>=0){
this.text.setselectionstart(i);
this.text.setselectionend(i+str.length());
this.statubar.settext("已经在:"+i+" 位置找到!");
}
else{
nextfindstr(str,++cur,end);
}

}
}
void upfindstr(string str,int cur){
if(cur<0){
this.statubar.settext("没有找到!");
}else{
int i=this.text.gettext().lastindexof(str);
if(i>=0){
this.text.setselectionstart(i);
this.text.setselectionend(i+str.length());
this.statubar.settext("已经在:"+i+" 位置找到!");
}else{
upfindstr(str,--cur);
}
}
}
void replacestr(string findstr,string replacestr,int cur,int end){
if(cur>end){
this.statubar.settext("没有找到!");
}else{
int i=this.text.gettext().indexof(findstr);
if(i>0){
this.text.setselectionstart(i);
this.text.setselectionend(i+findstr.length());
this.text.replacerange(replacestr,this.text.getselectionstart(),this.text.getselectionend());
}else{
replacestr(findstr,replacestr,++cur,end);
}
}

}

/*------------------------------------------------
*
* main
*
*-----------------------------------------------
*/

public static void main(string[] args){
jsb jsb1=new jsb();
}
}

/************************************************************
///////////////////////// event class ///////////////////////
**************************************************************/
class jsb_frame_closingadapter extends java.awt.event.windowadapter{
jsb adaptee;
jsb_frame_closingadapter(jsb adaptee){
this.adaptee=adaptee;
}

public void windowclosing(windowlistener e){
adaptee.frame_windowclose_windowclosing(e);
}
}
///////////////////////////////////////////////////////////
class jsb_text_mouseadapter extends java.awt.event.mouseadapter{
jsb adaptee;
jsb_text_mouseadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void mouseclicked(mouseevent e){
adaptee.text_mouseclicked(e);
}
}
class jsb_text_ancestoradapter implements javax.swing.event.ancestorlistener{
jsb adaptee;
jsb_text_ancestoradapter(jsb adaptee){
this.adaptee=adaptee;
}
public void ancestoradded(ancestorevent e){
adaptee.text_ancestoradded(e);
}
public void ancestorremoved(ancestorevent e){
}
public void ancestormoved(ancestorevent e){
}
}
class jsb_text_caretadapter implements javax.swing.event.caretlistener{
jsb adaptee;
jsb_text_caretadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void caretupdate(caretevent e){
adaptee.text_caretupdate(e);
}
}

///////////////////////////////////////////////////////////
class file_open_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
file_open_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.file_open_actionperformed(e);
}
}

class file_new_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
file_new_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.file_new_actionperformed(e);
}
}

class file_save_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
file_save_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.file_save_actionperformed(e);
}
}

class file_saveas_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
file_saveas_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.file_saveas_actionperformed(e);
}
}
class file_quite_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
file_quite_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.file_quite_actionperformed(e);

}
}
//////////////////////////////////////////////////////////////
class edit_undo_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
edit_undo_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.edit_undo_actionperformed(e);
}
}

class edit_cut_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
edit_cut_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.edit_cut_actionperformed(e);
}
}

class edit_copy_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
edit_copy_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.edit_copy_actionperformed(e);
}
}

class edit_paste_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
edit_paste_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.edit_paste_actionperformed(e);
}
}

class edit_delete_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
edit_delete_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.edit_delete_actionperformed(e);
}
}

class edit_find_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
edit_find_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.edit_find_actionperformed(e);
}
}

class edit_replace_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
edit_replace_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.edit_replace_actionperformed(e);
}
}

class edit_selectall_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
edit_selectall_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.edit_selectall_actionperformed(e);
}
}

class edit_timedate_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
edit_timedate_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.edit_timedate_actionperformed(e);
}
}
/////////////////////////////////////////////////////////////
class format_word_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
format_word_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.format_word_actionperformed(e);
}
}

class format_font_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
format_font_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.format_font_actionperformed(e);
}
}

class format_color_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
format_color_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.format_color_actionperformed(e);
}
}
///////////////////////////////////////////////////////////////

class help_about_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
help_about_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.help_about_actionperformed(e);
}
}

///////////////////////////////////////////////////////////
class pop_undo_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
pop_undo_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.pop_undo_actionperformed(e);
}
}

class pop_cut_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
pop_cut_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.pop_cut_actionperformed(e);
}
}

class pop_copy_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
pop_copy_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.pop_copy_acionperformed(e);
}
}

class pop_paste_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
pop_paste_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.pop_paste_actionperformed(e);
}
}

class pop_delete_actionadapter implements java.awt.event.actionlistener{
jsb adaptee;
pop_delete_actionadapter(jsb adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.pop_delete_actionperformed(e);
}
}

/******************* event class end **********************************/
/*************************************************************
* title: dlgtext.java
* author: jeason
* date: 2004-12-21
**************************************************************/
package jeason;

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

public class dlgtext extends jdialog{
private boolean check=false;

jlabel text=new jlabel( );
jbutton btnok=new jbutton( );
jbutton btnno=new jbutton( );

flowlayout flowlayout1=new flowlayout();

dlgtext(){
this(null,"",false);
}

dlgtext(frame frame, string title, boolean modal){
super(frame,title,modal);

text.settext(" 你要保存吗? ");
text.setsize(200,60);

this.setsize(200,80);
this.setmodal(true);

btnok.settext("确定(y)");
btnok.setmnemonic(´y´);
btnok.setsize(100,20);
btnok.addactionlistener(new btnok_actionadapter(this));


btnno.settext("取消(n)");
btnno.setmnemonic(´n´);
btnno.setsize(100,20);
btnno.addactionlistener(new btnno_actionadapter(this));


this.getcontentpane().setlayout(flowlayout1);
this.getcontentpane().add(text,flowlayout1);
this.getcontentpane().add(btnok,flowlayout1);
this.getcontentpane().add(btnno,flowlayout1);


}
void btnok_actionperformed(actionevent e){
this.check=true;
this.dispose();
this.hide();
}
void btnno_actionperformed(actionevent e){
this.check=false;
this.dispose();
this.hide();
}
public boolean getcheck(){
return this.check;
}

}

class btnok_actionadapter implements java.awt.event.actionlistener{
dlgtext adaptee;
btnok_actionadapter(dlgtext adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.btnok_actionperformed(e);
}
}

class btnno_actionadapter implements java.awt.event.actionlistener{
dlgtext adaptee;
btnno_actionadapter(dlgtext adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.btnno_actionperformed(e);
}
}
/******************************************************
*-----------------------------------------------------
* finddlg.java
* jeason
* 04-12-23 2:19
*-----------------------------------------------------
*****************************************************/

package jeason;

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

public class finddlg extends jdialog{

private string findstr;
private boolean flag=true;

jlabel findtext=new jlabel("查找内容");
jtextfield strtext=new jtextfield(" ");
jbutton btnnext=new jbutton( );
jbutton btnup=new jbutton( );

flowlayout flowlayout1=new flowlayout();

finddlg(frame frame,string title, boolean modal){
super(frame,title,modal);

this.settitle("查找");
this.setsize(200,90);
this.setmodal(true);

findtext.settext(" 查找内容 ");
findtext.setsize(70,60);

strtext.settext(" ");
strtext.setsize(130,60);

btnnext.settext("向下查找");
btnnext.setsize(100,40);
btnnext.addactionlistener(new btnnext_actionadapter(this));

btnup.settext("向上查找");
btnup.setsize(100,40);
btnup.addactionlistener(new btnup_actionadapter(this));

this.getcontentpane().setlayout(flowlayout1);
this.getcontentpane().add(this.findtext,flowlayout1);
this.getcontentpane().add(this.strtext,flowlayout1);
this.getcontentpane().add(this.btnnext,flowlayout1);
this.getcontentpane().add(this.btnup,flowlayout1);
}
finddlg(){
this(null,"",false);
}

public void btnnext_actionperformed(actionevent e){
this.findstr=this.strtext.gettext();
this.flag=true;
this.dispose();
}
public void btnup_actionperformed(actionevent e){
this.findstr=this.strtext.gettext();
this.flag=false;
this.dispose();
}
public string getfindstr(){
return this.findstr;
}
public boolean getflag(){
return this.flag;
}
}
class btnnext_actionadapter implements java.awt.event.actionlistener{
finddlg adaptee;
btnnext_actionadapter(finddlg adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.btnnext_actionperformed(e);
}
}

class btnup_actionadapter implements java.awt.event.actionlistener{
finddlg adaptee;
btnup_actionadapter(finddlg adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.btnup_actionperformed(e);
}
}

/******************************************************
*-----------------------------------------------------
* fontset.java
* jeason
* 04-12-23 2:19
*-----------------------------------------------------
*****************************************************/

package jeason;

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

public class fontset extends jdialog{

//jpanel panel1 = new jpanel();
private string font1="";
jlabel txtstr=new jlabel("请选择字体");
jlabel txt2=new jlabel("请选择字型");
list list1 = new list(3,false);
list list2 = new list(3,false);

jbutton btnok=new jbutton("确定");
jbutton btnno=new jbutton("撤销");
flowlayout flowlayout1=new flowlayout();

boolean flag=true;
int type;

fontset(frame frame,string title,boolean modal){
this.settitle("字体设置");
this.setsize(200,230);
this.setmodal(true);

txtstr.setsize(100,60);


list1.setsize(100,60);
list1.setmultiplemode(false);

this.txt2.setsize(100,60);

list2.setsize(100,60);

btnok.setmnemonic(´y´);
btnok.setsize(100,20);
btnok.addactionlistener(new btnok_actionadapter(this));


//btnno.settext("取消(n)");
btnno.setmnemonic(´n´);
btnno.setsize(100,20);
btnno.addactionlistener(new btnno_actionadapter(this));


///////////// font //////////////////////////////////

graphicsenvironment gl=graphicsenvironment.getlocalgraphicsenvironment();
string fontname[]=gl.getavailablefontfamilynames();
// int fontx[]={font.bold,font.italic,font.plain};


for(int i=0;i<fontname.length;i++){
list1.add(fontname[i]);
}
string fontx[]={"常规","斜体","粗体","粗斜体"};
for(int i=0;i<fontx.length;i++){
list2.add(fontx[i]);
}

list1.select(0);
list2.select(0);
///////////////////////////////////////////////

this.getcontentpane().setlayout(flowlayout1);

this.getcontentpane().add(txtstr,flowlayout1);
this.getcontentpane().add(list1,flowlayout1);
this.getcontentpane().add(this.txt2,flowlayout1);
this.getcontentpane().add(this.list2,flowlayout1);
this.getcontentpane().add(btnok,flowlayout1);
this.getcontentpane().add(btnno,flowlayout1);
}
fontset(){
this(null,"",false);
}
void btnok_actionperformed(actionevent e){
this.flag=true;
this.font1=this.list1.getselecteditem();
this.type=this.list2.getselectedindex();
this.dispose();
}
void btnno_actionperformed(actionevent e){
this.flag=false;
this.dispose();
}

public string font1(){
return this.font1;
}
public int font2(){

return this.type;
}
}

class btnok_actionadapter implements java.awt.event.actionlistener{
fontset adaptee;
btnok_actionadapter(fontset adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.btnok_actionperformed(e);
}
}

class btnno_actionadapter implements java.awt.event.actionlistener{
fontset adaptee;
btnno_actionadapter(fontset adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.btnno_actionperformed(e);
}
}

/**************************************************************
*-------------------------------------------------------------
* replacedlg.java
* jeason
* 04-12-23
*-------------------------------------------------------------
**************************************************************/

package jeason;

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

public class replacedlg extends jdialog{

private string findstr="",replacestr="";
///////////////////////////////////////
jlabel txt1=new jlabel("查找:");
jlabel txt2=new jlabel("替换为:");
jtextfield txtfind=new jtextfield(" ");
jtextfield txtreplace=new jtextfield(" ");
jbutton btn=new jbutton("替换");
flowlayout flowlayout1=new flowlayout();

replacedlg(frame frame,string title,boolean modal){
super(frame,title,modal);

this.settitle("替换为");
this.setsize(200,90);
this.setmodal(true);

txt1.setsize(40,60);
txt2.setsize(40,60);
txtfind.setsize(50,60);
txtreplace.setsize(50,60);

btn.setsize(200,20);
btn.addactionlistener(new btn_actionadapter(this));

this.getcontentpane().setlayout(flowlayout1);
this.getcontentpane().add(txt1,flowlayout1);
this.getcontentpane().add(this.txtfind,flowlayout1);
this.getcontentpane().add(this.txt2,flowlayout1);
this.getcontentpane().add(this.txtreplace,flowlayout1);
this.getcontentpane().add(this.btn,flowlayout1);

}
replacedlg(){
this(null,"",false);
}
public void btn_actionperformed(actionevent e){
this.findstr=this.txtfind.gettext();
this.replacestr=this.txtreplace.gettext();
this.dispose();
}
public string findstr(){
return this.findstr;
}
public string replacestr(){
return this.replacestr;
}

}
class btn_actionadapter implements java.awt.event.actionlistener{
replacedlg adaptee;
btn_actionadapter(replacedlg adaptee){
this.adaptee=adaptee;
}
public void actionperformed(actionevent e){
adaptee.btn_actionperformed(e);
}
}

/*********************************************
*------------------------------------------
* aboutdlg.java
* jeason
*----------------------------------------------
*********************************************/

package jeason;

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

public class aboutdlg extends jframe{

jlabel text=new jlabel("");
jlabel bar=new jlabel("");

final borderlayout borderlayout1=new borderlayout();

aboutdlg(){
super();
this.setsize(300,150);
this.settitle("~关于作者~");
text.settext("本记事本作者:杨勇"+"e-mail:yangyong@ccsu.cn");
bar.settext("本软件由jcreator 2.5开发");
jpanel jpanel=new jpanel();
jpanel.setlayout(borderlayout1);
jpanel.add(text,borderlayout1.center);
jpanel.add(bar,borderlayout1.south);

this.getcontentpane().add(jpanel);

this.setvisible(true);
}

}
 
 
上一篇: 用java 实现 http 的断点续传    下一篇: 用java编写自己的机器人,然后一起“厮杀” cyman20(翻译)
  相关文档
[原创] java数据库字符国际化 11-17
开发技术:kettle java api 开发实战记录 11-17
基于范型的java函数式编程(一) 11-17
新手入门:java中class类工作原理详解 11-16
用xml+jsp实现网页内容动态显示的方案 11-30
使用java程序的泛型应该注意的几个地方 11-16
http://alex0700.j1.fjjsp.net 05-12
使用displaytag使列名显示中文的方法 01-29
入门:java中相对路径,绝对路径问题总结 12-24
数据类型 11-17
在web应用中使用xml文件配置数据源 11-17
用spring aop实现开发中松散耦合 11-16
结合struts和hibernate谈j2ee架构的数据表示 11-17
如何在jini,rmi和applet中实现代码签名 12-27
java语言中浅复制与深复制概念详细解析 11-22
基于mvc模式的struts框架研究与应用 11-16
使用 ejb 组件你需要了解些什么呢? 11-17
java企业应用系统框架的比较与选择 11-17
awt在鼠标滚轮和输入等事件上的支持 11-17
java学习推荐书籍 11-17
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
技术电话:13616026886
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息