|
-
Nov 18th, 2004, 03:55 PM
#1
Thread Starter
Frenzied Member
why is this not working?{resolved}
I have a JtextArea named textArea2 and I want to search for text and then select it.
My code is not working and I don't know what could possibly be wrong with it.
Code:
String textSearch = JOptionPane.showInputDialog("Enter a string to search for");
int left = textArea2.indexOf(textSearch);
int right = textArea2.lastIndexOf(textSearch);
textArea2.select(left,right);
Last edited by System_Error; Nov 18th, 2004 at 06:19 PM.
-
Nov 18th, 2004, 03:56 PM
#2
Thread Starter
Frenzied Member
I get 2 errors saying:
Cannot resolve symbol
method indexOf(String);
Cannot resolve symbol
method lastIndexOf(String);
-
Nov 18th, 2004, 05:24 PM
#3
textArea2 is a JTextArea, not a String.
Code:
String val = textArea2.getText();
int left = val.indexOf(searchString);
int right = left + searchString.length();
textArea2.setSelectionStart(left);
textArea2.setSelectionEnd(right);
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 18th, 2004, 06:19 PM
#4
Thread Starter
Frenzied Member
Thank you so much. I was starting to go crazy with this problem.
-
Nov 25th, 2004, 10:41 AM
#5
Frenzied Member
It's funny how VB always confuses people when moving to a new language. In VB, it wouldn't have sent the object itself, like in java, but it would have called a standard sub, the text() sub. This, although it's made to save time, is a really bad thing, because it often confuses new programmers to think that's the way of doing things. It's especially hard to move on to OOP when you've been doing VB for a while...
Just my 2 cents, hehe
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
-
Nov 25th, 2004, 10:50 AM
#6
Well, OOP is OOP and Procedural Programming is Procedural Programming. The shift from one to the other is confusing and often leads to bad design, but that's not only VB's fault - the switch from C to C++ has similar problems.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 25th, 2004, 10:59 AM
#7
Frenzied Member
Originally posted by CornedBee
Well, OOP is OOP and Procedural Programming is Procedural Programming. The shift from one to the other is confusing and often leads to bad design, but that's not only VB's fault - the switch from C to C++ has similar problems.
Agreed, but VB still does have a way of hiding certain things, that the user should be aware of. Though this is to increase user friendlyness, it does lead to confusion. If you understand WHY 2 + 2 = 4, you can determine that 2 + 3 = 5, but if you just take that 2 + 2 will always equal 4, you have no way of knowing what 2 + 3 is. That was generally my experience when moving on...
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|