- 论坛徽章:
- 0
|
import java.awt.*;
import java.net.*;
import java.sql.*;
import java.awt.event.*;
class DataWindow extends Frame implements ActionListener
{
TextField englishtext;
TextArea chinesetext;
Button button;
DataWindow()
{
super("英汉小辞典1.0版"
setBackground(Color.cyan);
setBounds(150,150,300,120);
setVisible(true);
englishtext = new TextField(16);
chinesetext = new TextArea(5,10);
button = new Button("金城快车"
Panel p1 = new Panel();
Panel p2 = new Panel();
p1.add(new Label("输入您要查找的英语单词");
p1.add(englishtext);
p2.add(button);
add(p1,"North"
add(p2,"South"
add(chinesetext,"Center"
chinesetext.setBackground(Color.pink);
button.addActionListener(this);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button)
{
chinesetext.setText("查询结果"
try
{
Liststudent();
}
catch(Exception ex)
{
System.out.println("通知您出错了"
}
}
}
public void Liststudent() throws SQLException
{
String cname = new String();
String ename = new String();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
}
catch(ClassNotFoundException e)
{
System.out.println("通知您数据库驱动加载失败了,具体原因为:"+e.getMessage());
}
try
{
Connection Ex1Con = DriverManager.getConnection("jdbcdbc:jctx"
Statement Ex1Stmt = Ex1Con.createStatement();
ResultSet rs= Ex1Stmt.executeQuery("select * from jctx");
while(rs.next())
{
ename = rs.getString("word");
cname = rs.getString("cn");
if(ename.equals(englishtext.getText()))
{
chinesetext.append("\n" + cname);
break;
}
}
Ex1Con.close();
}
catch(Exception exex)
{
System.out.println("我告诉你,就是连接那块出错了!");
}
if(chinesetext.getText().trim().equals("查询结果"))
{
chinesetext.append("\n" + "没有找到要找的单词");
}
}
}
public class E_C
{
public static void main(String []args)
{
DataWindow window = new DataWindow();
window.pack();
}
}
以上是源代码,开发环境JDK1.4.2
数据库采用JDBC-ODBC连接
表的字段有两个,都是字符型的,一个是cn,另一个是word
cn是汉语意思
word是英语单词
可不要忘记建立数据源呢???
[ 本帖最后由 勤学博思 于 2006-9-3 16:34 编辑 ] |
-
jctx.jpg
(13.44 KB, 下载次数: 26)
源代码运行后的界面,可以看看啊
|