
正文
实现搜索框的java代码 javaweb搜索框
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
用java代码实现一个功能:当按下F9键时,在百度搜索框输入”abc"这几个字母,要求使用keyPress()方法。
1 .应用场景
现在很多应用都有搜索联想功能,baidu,google,各种电商都有这种搜索智能提示功能,可以帮助用户尽快找到自己想要的,用户是比较懒的,所有这种还是比较常见的。如下图所示用户输入 “数据结构”,联想出下面的结果以及结果数量
2.实现原理
相关问答
Q1: 用Java如何实现搜索功能
web程序的话如下:
画一个页面
表单提交用户输入数据
控制器接收提交到业务层
业务层处理返回页面
搜索实际上就是一个查询 select * from XXX
Q2: java如何实现搜索功能。比如,输入txt就能搜索出这个文件夹内所有txt格式的文件。请给完整代码。
import java.io.*;
public class FileDemo{
public static void main(String[] args)throws Exception{
//第一个参数是文件路径,第二个参数是要搜索的文件扩展名
getFile("D:\\JavaDemo",".txt");
}
private static void getFile(String pathName, final String endsWith)throws Exception{
File file = new File(pathName);
if(!file.exists())
throw new RuntimeException("文件不存在,你检索个P呀。");
file.listFiles(new FileFilter(){
public boolean accept(File file){
if(file.getName().endsWith(endsWith)){
System.out.println(file.getName());
return true;
}else
return false;
}
});
}
}
Q3: 用java写了一个界面,要求实现搜索功能,怎么做~?
实现方式有多种,建议方式一:
1. 在页面制作好输入框input,并且定义动作为打开一个帧iframe;
2. 在帧里,执行动作为百度的链接。意思也就是百度执行的结果在我自己的iframe里打开
Q4: java编写的程序,搜索框如何实现搜索功能
实现搜索框的java代码你是要显示guanshan.html和shigushan.html实现搜索框的java代码??
用javascript跳转地址不就好了
scriptlocation.href='XXXXX/guanshan.html'/script
...另外实现搜索框的java代码,别用什么access呀,半残数据库.
Q5: java编写的GUI 怎么实现查找功能(使用搜索栏搜索)
/**
* 这个是最简单实现搜索框的java代码的实现 具体如何匹配 可以在actionListener里重写
* @author Jeky
*/
public class HighlightFrame extends JFrame {
private JButton searchButton;
private JTextArea area;
private JTextField key;
public HighlightFrame() {
key = new JTextField(20);
searchButton = new JButton("search");
searchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String text = area.getText();
String keyword = key.getText();
int index = text.indexOf(keyword);
if (index != -1) {
try {
while (index != -1) {
area.getHighlighter().addHighlight(index, index + keyword.length(), DefaultHighlighter.DefaultPainter);
index = text.indexOf(keyword, index + keyword.length());
}
} catch (BadLocationException ex) {
ex.printStackTrace();
}
} else {
JOptionPane.showMessageDialog(HighlightFrame.this, "Can't find keyword:" + keyword);
}
}
});
area = new JTextArea("This is a sample of highlighter.\n"
+ "You can enter a keyword and press search button.\n"
+ "Then the word will be highlighted in the text.\n"
+ "\n"
+ "For more information,\n"
+ "you can check javax.swing.text package.");
JPanel north = new JPanel();
north.add(key);
north.add(searchButton);
this.getContentPane().add(new JScrollPane(area));
this.getContentPane().add(north, BorderLayout.NORTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(350, 350);
this.setVisible(true);
}
public static void main(String[] args) {
new HighlightFrame();
}
}
实现搜索框的java代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于javaweb搜索框、实现搜索框的java代码的信息别忘了在本站进行查找喔。








