Java: Getting the contents of a search dialog box in text editor i am making
Hi all,
I am makinga text editor in Java :) I am trying to implement the search function but am having problems: I have a class called SearchDialog, which contains (amongst others) the following method: Code:
protected String getText() { Now I need to actually get this info. I am writing another method to do this. I need to get the string, and then I can use the indexOf() method to find the search string in a certain string. So far, my method looks like this: Code:
public void Search(){ Code:
non-static method getText() cannot be referenced from a static context |
I just made everything associated with the getText() method static as wel,, and it is working.
Is this bad design? Should I be doing this a different way? |
Are you using an InputDialog to get the input? If so it'll return the string entered once a button in the dialog is clicked, so you could have a method in your class
private String getSearchTerm(){ String input =null; input=JOptionPane.showInputDialog(blah...blah...blah); return input; } and you'll still be staying with the event driven notion of doing things |
Are you calling the Search function from main()? If so that's not a good way of doing it and would explain the static context.
|
No I'm calling it from another method outside of main.
The problem is, we are'nt allowed to modify the code the lecturer gave us for the SearchDialog class too much. I just added the static flags and now it works fine. Can't see whats wrong with doing that! |
All times are GMT -5. The time now is 07:33 AM. |