LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-23-2004, 07:26 AM   #1
ludeKing
Member
 
Registered: Jul 2003
Location: NSW. Australia
Distribution: Ubuntu, Fedora, Slackware
Posts: 181

Rep: Reputation: 30
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() {
return target.getText();
}
So therefore when one enters text in a search dialog box, the string that they enter is retrieved by this method.

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(){
	String searchString = searchDialog.getText();
	System.out.println("The search term is: " + searchString);
	//other command to come here, I am just testing at the moment.
    }
But I am getting this error:
Code:
non-static method getText() cannot be referenced from a static context
        String searchString = SearchDialog.getText();
                                          ^
Whats going wrong, why can't I access it? Please help!!!!
 
Old 04-23-2004, 08:11 AM   #2
ludeKing
Member
 
Registered: Jul 2003
Location: NSW. Australia
Distribution: Ubuntu, Fedora, Slackware
Posts: 181

Original Poster
Rep: Reputation: 30
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?
 
Old 04-23-2004, 12:56 PM   #3
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
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
 
Old 04-23-2004, 01:00 PM   #4
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 53
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.
 
Old 04-23-2004, 08:46 PM   #5
ludeKing
Member
 
Registered: Jul 2003
Location: NSW. Australia
Distribution: Ubuntu, Fedora, Slackware
Posts: 181

Original Poster
Rep: Reputation: 30
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Search this forum" text box maxfacta LQ Suggestions & Feedback 6 08-01-2005 12:27 AM
howto search contents of the packages longnam Slackware 4 04-01-2005 10:51 AM
problem transfering result of search to a dialog box JoannesX Programming 3 02-07-2005 05:59 AM
how to search files with specific contents ? sachinh Linux - Security 4 07-22-2004 08:00 AM
search all book *contents* @ amazon.com jimveta General 2 10-24-2003 12:37 AM


All times are GMT -5. The time now is 07:17 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration