Cut
Hi all, I am trying to get a cut function to work for a text editor, but am having some problems. Any assistance would be appreciated.
Here is what I have so far:
//This is in editor.java
//For Cut
public String getSelectedText(){
return getTextArea().getSelectedText();
}
publicint getSelectionStart(){
return select;
}
publicint getSelectionEnd(){
return selectend;
}
publicvoid replaceRange(String text,int start,int end){
text = selectedtx;
start = select;
end = selectend;
}
publicvoid cut(){
copystring = getSelectedText();
replaceRange("",getSelectionStart(),getSelectionEnd());
requestFocus();
}
//****************************************************************************
//This is in editormenuhandler.java
//the Cut case
if(arg.equals(Editor.editLabels[0]))
{
editor.cut();
if(Editor.VERBOSE)
System.err.println(Editor.editLabels[0] +
" has been selected");
}
Once again thanks for all help
PLease tell me if you need anything else
[2207 byte] By [
AdiVa] at [2007-11-27 6:24:04]

> PLease tell me if you need anything else
Yes, a question for one. You say "but am having some problems" but don't list the problems.
My suggestions:
1) List any specific problems and related questions you may have.
2) If you have received an error message, then the full text of this message.
3) Any thing you have tried already to remedy your problem.
If you ask a specific question, I may be able to give a specific answer.
Good luck.
/P
Fair Enough,
To answer your questions, I honestly do not see any error display where they usually do.(I use Eclipse and errors are usually shown up on the Console window.)
So I presume it is something I have not written. When I select the cut option(after highlighting the desired text), The text does not disapear like it should, but is copied, since when I select paste, the highligted text displays.
So really the only thing that does not work, is how the text is actually removed from the writing.
Not to get ahead of myself, but this brings up the only other problem I have in this program, when I paste something, it is pasted at the top of the screen adn not at teh desired location. This is really off the top of my head, but do I need like a buffer or something? I will add the paste code:
//Editor********************************
//For Paste
public void insert(String text, int pos){
getTextArea().insert(text,pos);
text = selectedtx;
pos = position;
}
public void paste(){
if(copystring.length()>0)
insert(copystring,getSelectionStart());
requestFocus();
}
//In Editormenuhandler****************************************************
//the Paste case
if(arg.equals(Editor.editLabels[2]))
{
editor.paste();
if(Editor.VERBOSE)
System.err.println(Editor.editLabels[2] +
" has been selected");
}
}
Once again, I am sorry for not providing enough information or acting a bit confusing, but I really am a novice and am trying to learn as much as possible.
Thanks Again
AdiVa at 2007-7-12 17:42:31 >
