📄 jsb.java
字号:
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);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -