Java 记事本代码
[日期:2011-11-05] |
来源:Linux社区
作者:afgasdg |
[字体:大 中 小]
|
- import Java.awt.*;
- import java.io.*;
- import java.util.*;
- import java.awt.datatransfer.*;
- import java.text.SimpleDateFormat;
- import javax.swing.JOptionPane;
-
-
-
-
-
-
-
- class EditClass extends Frame
- {
- NoteBookFrame notebookframe = null;
- Date nowdate;
- Clipboard clipboard = null;
- SimpleDateFormat dateformat;
- SearchFrame search=null;
- EditClass(NoteBookFrame p)
- {
- notebookframe = p;
- nowdate = new Date();
- search= new SearchFrame(notebookframe);
- clipboard = getToolkit().getSystemClipboard();
- dateformat = new SimpleDateFormat("'本地时间:' yyyy年MM月dd日 E HH时mm分 ");
- }
-
- public void Repeal()
- {
-
- JOptionPane.showMessageDialog(this,"由于本人能力有限故还没有实现,请谅解!","记事本",JOptionPane.WARNING_MESSAGE);
- }
- public void Cut()
- {
- String temp = notebookframe.textarea.getSelectedText();
- StringSelection text = new StringSelection(temp);
- clipboard.setContents(text,null);
- int start = notebookframe.textarea.getSelectionStart();
- int end = notebookframe.textarea.getSelectionEnd();
- notebookframe.textarea.replaceRange("",start,end);
- }
- public void Copy()
- {
- String temp = notebookframe.textarea.getSelectedText();
- StringSelection text = new StringSelection(temp);
- clipboard.setContents(text,null);
- }
- public void Stick()
- {
- Transferable contexts = clipboard.getContents(notebookframe);
- DataFlavor flavor = DataFlavor.stringFlavor;
- if(contexts.isDataFlavorSupported(flavor))
- {
- try{
- String str = (String)contexts.getTransferData(flavor);
- int start = notebookframe.textarea.getSelectionStart();
- int end = notebookframe.textarea.getSelectionEnd();
- notebookframe.textarea.replaceRange(str,start,end);
-
- }
- catch(Exception ee){}
- }
-
- }
- public void Delete()
- {
- String temp = notebookframe.textarea.getSelectedText();
- int start = notebookframe.textarea.getSelectionStart();
- int end = notebookframe.textarea.getSelectionEnd();
- notebookframe.textarea.replaceRange("",start,end);
-
- }
- public void LookUp()
- {
- searchfor();
- }
- public void LookUpNext()
- {
- if(!notebookframe.textarea.getText().equals(""))
- {
- search.nextShear();
- }
- else
- {
- JOptionPane.showMessageDialog(this,"文本内容不为空时才能使用该功能!","记事本",JOptionPane.WARNING_MESSAGE);
- }
-
- }
- public void Exchange()
- {
- searchfor();
- }
- public void Goto()
- {
- searchfor();
- }
- public void All()
- {
- notebookframe.textarea.selectAll();
- }
- public void TimeDate()
- {
- notebookframe.textarea.append(dateformat.format(nowdate));
- }
- public void searchfor()
- {
- if(!notebookframe.textarea.getText().equals(""))
- {
- search.setVisible(true);
- }
- else
- {
- JOptionPane.showMessageDialog(this,"文本内容不为空时才能使用该功能!","记事本",JOptionPane.WARNING_MESSAGE);
- }
- }
-
- }
评论声明
- 尊重网上道德,遵守中华人民共和国的各项有关法律法规
- 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
- 本站管理人员有权保留或删除其管辖留言中的任意内容
- 本站有权在网站内转载或引用您的评论
- 参与本评论即表明您已经阅读并接受上述条款
|
|
|
|