java编写的GUI 怎么实现查找功能:
package communitys.Connect;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class dxdsy extends JFrame implements ActionListener{
private JButton button = new JButton("搜索");
private JTextField textfile = new JPasswordField("请输入文件名称······");
public dxdsy()
{
this.setLayout(null);
this.setBounds(200,200, 500,500);
textfile.setBounds(1, 1, 100,20);
button.setBounds(1, 25, 80,80);
this.add(button);
this.add(textfile);
button.addActionListener(this);//添加事件监听
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public void actionPerformed(ActionEvent e) {
String sql = "select * from tablename where 条件 like '%"+textfile.getText()+"%'";
try {
Class.forName("驱动字符");
Connection conn = DriverManager.getConnection("驱动字符");
Statement sta = conn.createStatement();
ResultSet rs = sta.executeQuery(sql);
//这个rs集合当中就是想要的数据
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
}