初学JAVA,一个对你们很简单的问题,60分拿去,急用

核桃家 2012-04-03 07:03:43
public static void main(String[] args) throws Exception {
StringTest test = new StringTest();
test.indexSearcher("lucene");
}

public void indexSearcher(String s)throws Exception{

QueryParser paser = new QueryParser("content",new StandardAnalyzer());
Query query = paser.parse(s);
Searcher searcher = new IndexSearcher(INDEX_STORE_PATH);
Hits hit = searcher.search(query);
for(int i=0;i<hit.length();i++)
{
Document d = hit.doc(i);
String dname = d.get("path");
System.out.println(dname+" ");
}
}
刚学JAVA
这是其中的代码
我想做个可视化界面,上面做个按钮“查询”
一点“查询” 界面就会输出程序中 System.out.println(dname+" ");的结果
求高手改造一下上面的代码
在线等
...全文
104 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
核桃家 2012-04-04
  • 打赏
  • 举报
回复
非常感谢各位的支持 已经实现了
核桃家 2012-04-04
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

Java code
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;


public class StringTest extends JFrame implements ActionL……
[/Quote]
哥哥 你是不是少个 JTextArea
按照你这样写 内容不会显示到可视界面上 只显示在eclipse上面
lj6823467 2012-04-03
  • 打赏
  • 举报
回复
亲,先把SWING看下,学下GUI才做这个吧!!慢慢来别急,这个算是中级部分了
nskws 2012-04-03
  • 打赏
  • 举报
回复
楼主需要学习swing
ncist_jianeng 2012-04-03
  • 打赏
  • 举报
回复
忘了个方法frame.setVisible(true);
ncist_jianeng 2012-04-03
  • 打赏
  • 举报
回复
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;


public class StringTest extends JFrame implements ActionListener{
private String s;
public static void main(String[] args) throws Exception {
StringTest test = new StringTest();
StringTest test1 = new StringTest("lucene");
//test.indexSearcher("lucene");
}
public StringTest(){

}
public StringTest(String s){
this.s = s;
JFrame frame = new JFrame();
frame.setSize(100, 100);

JButton button = new JButton("查询");
button.addActionListener(this);
frame.add(button);

}

public void indexSearcher(String s)throws Exception{

QueryParser paser = new QueryParser("content",new StandardAnalyzer());
Query query = paser.parse(s);
Searcher searcher = new IndexSearcher(INDEX_STORE_PATH);
Hits hit = searcher.search(query);
for(int i=0;i<hit.length();i++)
{
Document d = hit.doc(i);
String dname = d.get("path");
System.out.println(dname+" ");
}
}
public void actionPerformed(ActionEvent e) {
try {
this.indexSearcher(s);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
yuppy 2012-04-03
  • 打赏
  • 举报
回复
在添加按钮的时候,给他初始化一个事件监听器.actionlistener之类的。 然后在里面调用你这个方法
孤独人生 2012-04-03
  • 打赏
  • 举报
回复
初学java就要做可视化的界面?看看gui或者java web把,不要那么急
m540920181 2012-04-03
  • 打赏
  • 举报
回复
单纯的java是写不出来的,要结合显示页面才能的
成一粒 2012-04-03
  • 打赏
  • 举报
回复
怎么改?你自己写好了。哪儿报错了?贴出错误代码

50,542

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧