import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.net.*;
class f1 extends Frame implements ActionListener
{
Label label;
TextField text1;
TextArea text2;
Button button;
Panel panel1,panel2;
f1()
{
super("英汉小词典");
setBackground(Color.cyan);
setBounds(100,120,800,600);
setVisible(true);
text1=new TextField(15);
text2=new TextArea(5,10);
button=new Button("OK");
label=new Label("输入要查询的单词");
panel1=new Panel();
panel2=new Panel();
add(panel1,"North");add(panel2,"South");add(text2,"Center");
panel1.add(label);panel1.add(text1);
panel2.add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button)
{
text2.setText("查询结果");
try{Do();}
catch(SQLException ee){}
}
}
public void Do() throws SQLException
{
String cname,ename;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e){}
Connection con=DriverManager.getConnection("jdbc.odbc:XYZ","","");
Statement sql=con.createStatement();
ResultSet rs=sql.executeQuery("SELECT * FROM chaxun ");
while (rs.next())
{
ename=rs.getString("英文");
cname=rs.getString("中文");
if(ename.equals(text1.getText()))
{
text2.append('\n'+cname);
}
}
}
}
public class Data
{
public static void main(String arg[])
{
f1 f=new f1();
}
}