[英]Passing data from one class to another in Java
I am trying to pass an output to a text area. 我试图将输出传递到文本区域。
I have Class Search
which handles all the searching and display the output using System.out.println()
. 我有
Class Search
,它使用System.out.println()
处理所有搜索并显示输出。
I have created Class GUI
in order to make the console output (System.out.println())
appear in the JTextArea
. 我创建了
Class GUI
,以使控制台输出(System.out.println())
出现在JTextArea
。
I am trying to pass that data into the text area using objects but I dont know why it is not working. 我试图使用对象将数据传递到文本区域,但我不知道为什么它不起作用。
Class Search
has this method that calculates the output: Class Search
有这个计算输出的方法:
public static void searchIndex(String searchString) throws IOException, ParseException
Class GUI
has the text1
Class GUI
具有text1
In Class GUI I have tried this: 在类GUI中我试过这个:
text1.setText(Search.searchIndex(searchString));
but it is giving me an error searchString cannot be resolved to a variable
但它给我一个错误
searchString cannot be resolved to a variable
Any suggestions ? 有什么建议么 ?
Regards. 问候。
The method is not returning: 该方法未返回:
public static void searchIndex(String searchString) throws IOException, ParseException {
Need to change void
to String
and also return the result: 需要将
void
更改为String
并返回结果:
public static String searchIndex(String searchString) throws IOException, ParseException {
//do search
return resultString;
}
For the following to work: 为了以下工作:
text1.setText(Search.searchIndex(searchString));
searchString cannot be resolved to a variable
searchString无法解析为变量
The above error is caused by the fact that you are trying to use the variable "searchString" without declaring it. 上述错误是由于您尝试使用变量“searchString”而未声明它而引起的。
String searchString = "Some string that is in the search index";
text1.setText(Search.searchIndex(searchString));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.