我试过这种编码,在我的文本编辑器中查找和替换按钮,但无法正常工作。文本编辑器中的“查找并替换文本”按钮中的错误
public void actionPerformed(ActionEvent ae)
{
String findwhat = new String("");
String replacewith = new String("");
String text = ta.getText();
findwhat = textField1.getText();
ln = findwhat.length();
replacewith = textField2.getText();
if (ae.getSource() == findButton)
{
startindex = text.indexOf(findwhat, i);
ta.select(startindex, startindex + ln);
i = startindex + ln;
}
else if (ae.getSource() == replace)
{
ta.replaceRange(replacewith, startindex, startindex + ln);
}
else if (ae.getSource() == replaceall)
{
while (startindex + ln != -1)
{
startindex = text.indexOf(findwhat, i);
ta.replaceRange(replacewith, startindex, startindex + ln);
}
}
}
有人能帮我吗?
_ “不工作” _是非常模糊的。它以什么方式不起作用?它是否会抛出异常?当它应该做什么时什么也不做?做错了什么?还有别的吗? – 2014-09-29 17:42:22
你是什么意思,“它不工作”?这段代码做了什么?你的[MCVE](http://stackoverflow.com/help/mcve)在哪里? – 2014-09-29 17:42:25
你需要解释什么是不工作。你期望它做什么,为什么?它实际上做的是什么 – 2014-09-29 17:42:46