在我的計劃,我通過索引搜索使用Lucene,我檢索文件。我從Lucene的搜索中爲檢索到的文檔創建了XML文件。現在,我想將這些XML文件作爲超鏈接並顯示給用戶作爲搜索結果。那是我想要XML文件在用戶點擊這個超鏈接時打開。任何幫助表示讚賞!?
for(int i=0;i<file_count;i++)
{
file=str+index[i]+".xml";
JLabel label = new JLabel(file,JLabel.CENTER);
label.setOpaque(true);
label.setBackground(Color.RED);
panel.add(label) ;
label.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
if(evt.getClickCount() > 0)
{
Runtime r= Runtime.getRuntime();
try {
System.out.println("testing : Inside mouseclicked");
Process p = r.exec("cmd.exe /c start "+file);
System.out.println("opened the file");
} catch (IOException ex) {
System.out.println(ex.getMessage());
System.out.println();
}
}
}
});
}
這是我所做的代碼。在這裏,我想在屏幕上輸出「file_count」no次數。我明白了,但是所發生的一切是所有鏈接在點擊時顯示相同的文件。幫幫我?
較短的問題:如何創建超鏈接到文件?答案:results – 2012-04-17 19:32:11
@ChadNC:我嘗試過JLabel,但是MouseClicked操作存在問題!假設我有三個文件作爲輸出顯示,並且當我使用JLabel的鼠標點擊事件時,在輸出面板中它顯示了所有三個鏈接的相同文件。該怎麼辦? – 2012-04-17 19:45:39
@SteveH .:不是HTML,我想用Java。 – 2012-04-17 19:46:59