一个简单的访问数据库的应用程序
2008-01-05 18:49:30 来源:WEB开发网file 1 :
先把主程序的父类搬来!
/*
* date: 2004-11-20
* author:zhangyu6050;
* todo:
* bugs:
*/
package sd;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public abstract class MyQQPan extends JFrame implements ActionListener
{
JTextArea textreceive=new JTextArea();
JTextArea textsend =new JTextArea("select * from Employees");
JButton button =new JButton ("Send");
public MyQQPan()
{
//init controls
setTitle("查询框架");
setBounds(50,50,500,400);
getContentPane().setLayout(null);
getContentPane().add(textreceive);
getContentPane().add(textsend);
getContentPane().add(button);
button.addActionListener(this);
textreceive.setBounds(0,0,450,300);
textsend.setBounds(10,320,350,60);
button.setBounds(370,320,70,30);
}
public abstract void actionPerformed(ActionEvent event);
}
file 2 :
下面是主程序!
/*
* date: 2004-11-19
* author:zhangyu6050;
* todo:
* bugs:
*/
package sd;
//TextAreaDemo.java
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import javax.swing.*;
import sd.MySQL;
public class Myframe extends MyQQPan{
PRivate String sql;
private String rsult;
// private int row;//要所取的列
public void actionPerformed(ActionEvent e){
if(e.getSource() instanceof JButton){
sql=textsend.getText();
// row= Character.getNumericValue(sql.charAt(sql.length()-1));//得到要取的列数!
// initRsult();
Methods.ting(sql);//这个类集成了一些常用的方法!
rsult=Methods.rStr;
textreceive.setText(rsult);
}
}
public static void main(String[] args) {
Myframe mf=new Myframe();
mf.setVisible(true);
}
更多精彩
赞助商链接