资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java记事本代码撤销 java记事本乱码

java 记事本的撤销 删除 查找 替换 这4个功能

你看看这个行不

目前创新互联已为近1000家的企业提供了网站建设、域名、网络空间、网站托管运营、企业网站设计、天水网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

public void Cut()

{

String temp = notebookframe.textarea.getSelectedText();//获得鼠标拖动选取的文本

StringSelection text = new StringSelection(temp);//把待剪切的文本传递给 text 对象

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);//把待剪切的文本传递给 text 对象

clipboard.setContents(text,null);//将文本放入剪切板中

}

public void Stick()

{

Transferable contexts = clipboard.getContents(notebookframe);//获取剪切板中的内容

DataFlavor flavor = DataFlavor.stringFlavor;//剪切板的风格(系统的标准风格)

if(contexts.isDataFlavorSupported(flavor))//判断风格java是否可用

{

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);

}

}

java如何实现记事本中的 撤销 功能

写一个栈,把前面的操作压入栈里,撤销的时候一个个出栈就可以了。。

java怎么实现记事本中的 撤销 功能

// ---------------创建撤消操作管理器

protected UndoManager undo = new UndoManager();

protected UndoableEditListener undoHandler = new UndoHandler();

// 撤消

else if (e.getSource() == mEdit_Undo || e.getSource() == popupMenu_Undo || e.getSource() == undoButton) {

Text.requestFocus();

if (undo.canUndo()) {

try {

undo.undo();

} catch (CannotUndoException ex) {

System.out.println("Unable to undo: " + ex);

ex.printStackTrace();

}

if (!undo.canUndo()) {

mEdit_Undo.setEnabled(false);

popupMenu_Undo.setEnabled(false);

undoButton.setEnabled(false);

}

}

}

//兄弟连Java战狼班


当前文章:java记事本代码撤销 java记事本乱码
浏览路径:http://cdkjz.cn/article/dohssoj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220