我写的一个java记事本,有加密解密和大小写转换功能 |
import java.awt.*;import java.awt.event.*;import java.io.*;
public class Notepad /*implements ActionListener , MouseListener , MouseMotionListener , WindowListener , ItemListener , KeyListener, TextListener */{ //成员变量 private Frame mainFrame;//主框架 private MenuBar mb ; //菜单条 private Menu mFile , mEdit , mFormat , mHelp ; //菜单:文件,编辑,格式,帮助 private MenuItem miNew , miOpen , miSave , miSaveAs , miExit ;//文件菜单项:新建,打开,保存,另存为,退出 private MenuItem miCut , miCopy , miPaste , miDelete ;//编辑菜单项:剪切,复制,粘贴,删除 private MenuItem miFont , miLowtoCapital, miCapitaltoLow ,miEncrypt , miDisencrypt;//格式菜单项:字体 private MenuItem miAboutNotepad;//帮助菜单项:关于记事本 private TextArea ta;//文本区 private String tempString;//临时字符串,用于存储需要复制粘贴的字符串 private boolean textValueChanged = false; private int id_font ;//字体 String fileName = "";//上次保存后的文件名和地址 //构造函数 public Notepad(){ //框架 mainFrame = new Frame ("Notepad v0.99 by Launching"); mb = new MenuBar (); ta = new TextArea (30 ,60); ta.setFont( new Font ( "Times New Rome" , Font.PLAIN , 15)); ta.setBackground(new Color(0 , 250 , 200)); //菜单条 mFile = new Menu ( "File"); mEdit = new Menu ( "Edit"); mFormat = new Menu ("Format"); mHelp = new Menu ("Help"); //"文件" miNew = new MenuItem ("New"); miOpen = new MenuItem ("Open"); miSave = new MenuItem ("Save"); miSaveAs = new MenuItem ("Save as"); miExit = new MenuItem ("Exit"); //"编辑" miCut = new MenuItem ("Cut"); miCopy = new MenuItem ("Copy"); miPaste = new MenuItem ("Paste"); miDelete = new MenuItem ("Delete"); //"格式" miFont = new MenuItem ("Font"); miLowtoCapital = new MenuItem("Low to Capital"); miCapitaltoLow = new MenuItem("Capital to Low"); miEncrypt = new MenuItem("Encrypt"); miDisencrypt = new MenuItem("Disencrypt"); //"帮助" miAboutNotepad = new MenuItem ("About Notepad"); //添加文件菜单项 mFile.add(miNew); mFile.add(miOpen); mFile.add(miSave); mFile.add(miSaveAs); mFile.add(miExit); //添加编辑菜单项 mEdit.add(miCut); mEdit.add(miCopy); mEdit.add(miPaste); mEdit.add(miDelete); //添加格式菜单项 mFormat.add(miFont); mFormat.add(miLowtoCapital); mFormat.add(miCapitaltoLow); mFormat.add(miEncrypt); mFormat.add(miDisencrypt); //添加帮助菜单项 mHelp.add(miAboutNotepad); //菜单条添加菜单 mb.add(mFile); mb.add(mEdit); mb.add(mFormat); mb.add(mHelp); //框架添加菜单条 mainFrame.setMenuBar( mb ); //初始字符串赋为空 tempString = ""; //添加文本区 mainFrame.add(ta, BorderLayout.CENTER); mainFrame.setSize(800 , 500); mainFrame.setLocation( 100 ,100);// 起始位置 mainFrame.setResizable(true);//不可更改大小 mainFrame.setVisible(true); //mainFrame.pack();
////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////增加监视器//////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// //主框架 mainFrame.addWindowListener(new WindowAdapter (){ //关闭窗口 public void windowClosing(WindowEvent e) { System.exit(0); } }); //文本区 ta.addKeyListener( new KeyAdapter(){ public void KeyTyped(KeyEvent e){ textValueChanged = true ; //键盘按键按下即导致文本修改 } }); ////////////////"文件"菜单:////////////////////// //新建 miNew.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ ta.replaceRange("", 0 , ta.getText().length()) ;//清空文本区的内容 fileName = "";//文件名清空 } }); //打开 miOpen.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { FileDialog d=new FileDialog(mainFrame , "open file" , FileDialog.LOAD );//打开文件对话框 d.addWindowListener( new WindowAdapter(){ //关闭文件对话框窗口 public void windowClosing(WindowEvent ee){ System.exit(0); } }); d.setVisible(true); File f = new File( d.getDirectory()+d.getFile() ); //建立新文件 fileName = d.getDirectory()+d.getFile();//得到文件名 char ch[] = new char [(int)f.length()];///用此文件的长度建立一个字符数组 try//异常处理 { //读出数据,并存入字符数组ch中 BufferedReader bw = new BufferedReader( new FileReader(f) ); bw.read(ch); bw.close(); } catch( FileNotFoundException fe ){ System.out.println("file not found"); System.exit(0); } catch( IOException ie){ System.out.println("IO error"); System.exit(0); } String s =new String (ch); ta.setText(s);//设置文本区为所打开文件的内容 } }); //保存 miSave.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { if( fileName.equals("") ){ //如果文件没有被保存过,即文件名为空 FileDialog d=new FileDialog(mainFrame , "save file" , FileDialog.SAVE );//保存文件对话框 d.addWindowListener( new WindowAdapter(){ //关闭文件对话框窗口 public void windowClosing(WindowEvent ee){ System.exit(0); } }); d.setVisible(true); String s = ta.getText();//得到所输入的文本内容 try//异常处理 { File f = new File( d.getDirectory()+d.getFile());//新建文件 fileName = d.getDirectory()+d.getFile();//得到文件名 BufferedWriter bw = new BufferedWriter( new FileWriter (f));//输入到文件中 bw.write(s , 0 , s.length()); bw.close(); } catch(FileNotFoundException fe_){ System.out.println("file not found"); System.exit(0); } catch( IOException ie_) { System.out.println(" IO error"); System.exit(0); } } else //如果文件已经保存过 { String s = ta.getText();//得到所输入的文本内容 try//异常处理 { File f = new File( fileName );//新建文件 BufferedWriter bw = new BufferedWriter( new FileWriter (f));//输入到文件中 bw.write(s , 0 , s.length()); bw.close(); } catch(FileNotFoundException fe_){ System.out.println("file not found"); System.exit(0); } catch( IOException ie_) { System.out.println(" IO error"); System.exit(0); } } } }); //另存为 miSaveAs.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { FileDialog d=new FileDialog(mainFrame , "save file" , FileDialog.SAVE );//保存文件对话框 d.addWindowListener( new WindowAdapter(){ //关闭文件对话框窗口 public void windowClosing(WindowEvent ee){ System.exit(0); } }); d.setVisible(true); String s = ta.getText();//得到所输入的文本内容 try//异常处理 { File f = new File( d.getDirectory()+d.getFile());//新建文件 BufferedWriter bw = new BufferedWriter( new FileWriter (f));//输入到文件中 bw.write(s , 0 , s.length()); bw.close(); } catch(FileNotFoundException fe_){ System.out.println("file not found"); System.exit(0); } catch( IOException ie_) { System.out.println(" IO error"); System.exit(0); } } }); //退出 miExit.addActionListener( new ActionListener(){ ///退出程序 public void actionPerformed(ActionEvent e){ System.exit(0); } }); ////////////////"编辑"菜单://////////////////// //剪切 miCut.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ tempString = ta.getSelectedText(); ///得到要复制的内容,暂存在tempString中 StringBuffer tmp = new StringBuffer ( ta.getText());//临时存储文本 int start = ta.getSelectionStart(); //得到要删除的字符串的起始位置 int len = ta.getSelectedText().length(); //得到要删除的字符串的长度 tmp.delete( start , start+len); ///删除所选中的字符串 ta.setText(tmp.toString());//用新文本设置原文本 } }); //复制 miCopy.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ tempString = ta.getSelectedText(); ///得到要复制的内容,暂存在tempString中 } }); //粘贴 miPaste.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ StringBuffer tmp = new StringBuffer ( ta.getText());//临时存储文本 int start = ta.getSelectionStart(); //得到要粘贴的位置 tmp.insert(start , tempString);//查入要粘贴的内容 ta.setText(tmp.toString());//用新文本设置原文本 } }); //删除 miDelete.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ StringBuffer tmp = new StringBuffer ( ta.getText());//临时存储文本 int start = ta.getSelectionStart(); //得到要删除的字符串的起始位置 int len = ta.getSelectedText().length(); //得到要删除的字符串的长度 tmp.delete( start , start+len); ///删除所选中的字符串 ta.setText(tmp.toString());//用新文本设置原文本 } }); ////////////////"格式"菜单://////////////////// //字体 miFont.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ final Dialog d = new Dialog ( mainFrame , "Font");//新建对话框 d.setLocation( 250 ,250);// 起始位置 d.setLayout( new BorderLayout());//表格布局 //////////////////////////上部分面板 Label l_font = new Label ("font");//font标签 Panel p_1 = new Panel(); p_1.add(l_font); p_1.setVisible(true); //////////////////////////中部分面板 List font_list = new List (6 , false);//字体列表 //添加字体项目 font_list.add("Plain");///普通字体 font_list.add("Bold"); ///粗体 font_list.add("Italic");//斜体 font_list.addItemListener( new MyItemListener_font() ); //字体增加监视器 Panel p_2 = new Panel(); p_2.add(font_list); p_2.setVisible(true); //////////////////////////下部分面板 Button ok = new Button ("OK"); ok.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ d.dispose(); } }); ok.setSize( new Dimension (20 , 5) ); Panel p_3 = new Panel();//下部分面板 p_3.add(ok); p_3.setVisible(true); //添加三个面板 d.add(p_1 , BorderLayout.NORTH); d.add(p_2 , BorderLayout.CENTER); d.add(p_3 , BorderLayout.SOUTH); d.pack(); d.addWindowListener( new WindowAdapter(){ //关闭对话框窗口 public void windowClosing(WindowEvent ee){ d.dispose(); } }); d.setVisible(true); } }); //小写字母转大写 miLowtoCapital.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ String s = ta.getText();//得到所输入的文本内容 StringBuffer temp = new StringBuffer(""); for(int i = 0 ; i<s.length() ; i++){ if((int)s.charAt(i)>=97 && (int)s.charAt(i)<=122 ){ temp.append((char)((int)s.charAt(i)-32)); } else temp.append(s.charAt(i)); } s = new String(temp); ta.setText(s); } }); //大写字母转小写 miCapitaltoLow.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ String s = ta.getText();//得到所输入的文本内容 StringBuffer temp = new StringBuffer(""); for(int i = 0 ; i<s.length() ; i++){ if((int)s.charAt(i)>=65 && (int)s.charAt(i)<=90 ){ temp.append((char)((int)s.charAt(i)+32)); } else temp.append(s.charAt(i)); } s = new String(temp); ta.setText(s); } }); //加密 miEncrypt.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ String s = ta.getText();//得到所输入的文本内容 StringBuffer temp = new StringBuffer(""); for(int i = 0 ; i<s.length() ; i++){ if(s.charAt(i)>=40 && s.charAt(i)<=125){ if(i%2==0){ temp.append((char)(s.charAt(i) + 1 )); } else temp.append((char)(s.charAt(i) - 1 )); } else temp.append(s.charAt(i)); } s = new String(temp); ta.setText(s); } }); //解密 miDisencrypt.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ String s = ta.getText();//得到所输入的文本内容 StringBuffer temp = new StringBuffer(""); for(int i = 0 ; i<s.length() ; i++){ if(s.charAt(i)>=40 && s.charAt(i)<=125){ if(i%2==0){ temp.append((char)(s.charAt(i) - 1 )); } else temp.append((char)(s.charAt(i) + 1 )); } else temp.append(s.charAt(i)); } s = new String(temp); ta.setText(s); } }); ////////////////"帮助"菜单://////////////////// //关于记事本 miAboutNotepad.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ final Dialog d = new Dialog ( mainFrame , "AboutNotepad");//新建对话框 TextArea t = new TextArea("\nwelcome to use Notepad " + "\n\n" + "Copyright@Launching " + "\n\n" + "free software" + "\n\n" + "v0.99");//添加标签 t.setSize( new Dimension ( 5 , 5)); t.setEditable(false); d.setResizable(false);//不可调整大小 d.add(t); d.pack(); d.addWindowListener( new WindowAdapter(){ //关闭对话框窗口 public void windowClosing(WindowEvent ee){ d.dispose(); } }); d.setLocation( 100 ,250);// 起始位置 d.setVisible(true); } }); } class MyItemListener_font implements ItemListener { //字体监听器 public void itemStateChanged(ItemEvent e) { id_font = ((java.awt.List)e.getSource()).getSelectedIndex(); switch( id_font){ case 0:{ ta.setFont(new Font("Times New Roman", Font.PLAIN ,ta.getFont().getSize()) );//普通文字 break; } case 1:{ ta.setFont(new Font("Times New Roman" , Font.BOLD ,ta.getFont().getSize()) );//粗体文字 break; } case 2:{ ta.setFont(new Font("Times New Roman" , Font.ITALIC ,ta.getFont().getSize()) );//斜体文字 break; } } } } /////////////////////////////////////////主函数/////////////////////////////////////////////////// public static void main(String arg[]){ Notepad test = new Notepad(); ///创建记事本 }//////////////////////////////////////////////////////////////////////////////////////////////////}
这是程序的jar包,机器装了jre的话可以双击直接运行 500)this.width=500'>Notepad.rar
|
|
回复:我写的一个java记事本,有加密解密和大小写转换功能 |
老猪(游客)发表评论于2008/4/10 19:46:25 | 我拷到手机上后运行,出现启动 返回 没有其他选项?为什么?
|
|
回复:我写的一个java记事本,有加密解密和大小写转换功能 |
123(游客)发表评论于2008/1/10 14:57:35 |
|
|
回复:我写的一个java记事本,有加密解密和大小写转换功能 |
qingqing(游客)发表评论于2007/10/25 15:26:44 | 写得很好
|
|
回复:我写的一个java记事本,有加密解密和大小写转换功能 |
guoke(游客)发表评论于2007/6/9 8:40:48 | good!!!!!!!!!!
|
|
回复:我写的一个java记事本,有加密解密和大小写转换功能 |
程序员(游客)发表评论于2007/1/4 13:58:17 | 不错呀。哈哈~不过外观欠缺了点.加油哦~~改进一下吧~
|
|
回复:我写的一个java记事本,有加密解密和大小写转换功能 |
malajisi(游客)发表评论于2006/10/4 23:52:29 | 结构清晰
格式良好
不错~~
|
|
回复:我写的一个java记事本,有加密解密和大小写转换功能 |
不好意思啊各位,上个学期由于一个特别的原因(是啥原因我就不说了),我把这里java记事本的程序给删了,现在贴上,以飨大家:)
|
|
回复:我写的一个java记事本,有加密解密和大小写转换功能 |
willing(游客)发表评论于2006/6/7 9:00:17 | 哪里有啊?哪里下的
|
|
回复:我写的一个java记事本,有加密解密和大小写转换功能 |
XIAO(游客)发表评论于2006/4/19 2:42:14 | 回复:我写的一个java记事本,有加密解密和大小写转换功能
|
|
回复:我写的一个java记事本,有加密解密和大小写转换功能 |
散播(游客)发表评论于2006/3/8 20:31:04 | 哪里下啊
|
|
回复:我写的一个java记事本,有加密解密和大小写转换功能 |
汉语列表?是什么?我的qq:71850180 :)
|
|
回复:我写的一个java记事本,有加密解密和大小写转换功能 |
海洋之心(游客)发表评论于2006/1/6 19:07:24 | 哥们你的设计很厉害,要是汉语的下拉列表就更好了,你一定是个高手了,有时间教教我啊,我的qq/290023302希望和你尽快联系啊.
|
|
回复:我写的一个java记事本,有加密解密和大小写转换功能 |
不错不错
|
|
» 1 »
|

.: 公告
|
« | July 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | |
|
.: 我的分类(专题)
|

.: 最新日志
.: 最新回复
|

blog名称:Launching Is Launching 日志总数:36 评论数量:79 留言数量:1 访问次数:229570 建立时间:2005年12月11日 |
|

.: 留言板
|

.: 链接
|

|