国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

用Java編寫的記事本程序(2)

2019-11-17 05:55:33
字體:
來源:轉載
供稿:網友
 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.AP
PROVE_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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乐山市| 辉县市| 常熟市| 陇西县| 崇仁县| 上思县| 若羌县| 北流市| 林口县| 庆阳市| 峡江县| 基隆市| 临汾市| 周至县| 锡林郭勒盟| 峡江县| 新疆| 邯郸市| 剑河县| 三门县| 收藏| 全州县| 鹤山市| 五家渠市| 通许县| 镇康县| 承德市| 将乐县| 崇阳县| 兴业县| 兰考县| 泰宁县| 定襄县| 昭平县| 法库县| 永德县| 峨眉山市| 浦东新区| 万盛区| 冷水江市| 铜陵市|