这是我在Eclipse里写的一段代码,为什么显示没错,运行出来所有按钮都没用???谢谢哪位高手帮忙看哈~^_^
ZZDTT 2010-01-04 12:45:27 package zz;
import tt.chuang;
public class Example
{
public static void main(String args[])
{
tt.chuang chu=new tt.chuang();
}
}
package tt;
import javax.swing.*;
import yy.copy.police;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.awt.*;
import java.awt.event.*;
public class chuang extends JFrame {
//implements ActionListener{
public static JButton firstBtn,nextBtn,lastBtn,addBtn;
public static JTextField Text1,Text2,Text3,Text4;
Box baseBox,boxV1,boxV2;
JPanel centerPanel,sPanel;
GridBagConstraints cnostraints;
public static int i;
public static String name,number,birthday,height;
public chuang(){
super("message");
setLayout(new BorderLayout());
centerPanel=new JPanel();
sPanel=new JPanel();
add(centerPanel,BorderLayout.CENTER);
add(sPanel,BorderLayout.SOUTH);
setVisible(true);
JLabel numberLabel=new JLabel("number");
JLabel nameLabel=new JLabel("name");
JLabel birthdayLabel=new JLabel("birthy");
JLabel highLabel=new JLabel("highLabel");
boxV1=Box.createVerticalBox();
boxV1.add(numberLabel);
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(nameLabel);
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(birthdayLabel);
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(highLabel);
Text1=new JTextField();
Text2=new JTextField();
Text3=new JTextField();
Text4=new JTextField();
boxV2=Box.createVerticalBox();
boxV2.add(new JTextField(16));
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(new JTextField(16));
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(new JTextField(16));
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(new JTextField(16));
baseBox=Box.createHorizontalBox();
baseBox.add(boxV1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(boxV2);
centerPanel.add(baseBox);
police po=new police();
firstBtn=new JButton("第一个");
firstBtn.addActionListener(po);
nextBtn=new JButton("下一个");
nextBtn.addActionListener(po);
lastBtn=new JButton("最后一个");
lastBtn.addActionListener(po);
addBtn=new JButton("添加记录");
addBtn.addActionListener(po);
sPanel.add(firstBtn);
sPanel.add(nextBtn);
sPanel.add(lastBtn);
sPanel.add(addBtn);
setBounds(120,125,400,250);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}
package yy.copy;
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 tt.chuang;
public class police implements ActionListener{
Connection con;
Statement sql;
ResultSet rs;
int i=0;
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==chuang.firstBtn){
try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(ClassNotFoundException e1){}
try { con=DriverManager.getConnection("jdbc:sqlsever://127.0.0.1:1433;DatabaseName=master","sa","QMPH6-VDV79-CRBCX-HQ32P-F84B3");
sql=con.createStatement
(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=sql.executeQuery("SELECT * FROM message");
int i=1;
rs.absolute(i);
String number=rs.getString(1);
String name=rs.getString(2);
String birth=rs.getString(3);
String height=rs.getString(4);
chuang.Text1.setText(chuang.number);
chuang.Text2.setText(chuang.name);
chuang.Text3.setText(chuang.birthday);
chuang.Text4.setText(chuang.height);
con.close(); }
catch(SQLException e2) {}
}
else
if(e.getSource()==chuang.nextBtn){
try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");}
catch(ClassNotFoundException e1){}
try { con=DriverManager.getConnection("jdbc:sqlsever://127.0.0.1:1433;DatabaseName=master","sa","QMPH6-VDV79-CRBCX-HQ32P-F84B3");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=sql.executeQuery("SELECT * FROM message");
int i=rs.getRow()+1;
rs.absolute(i); //游标移到这一行
String number=rs.getString(1);
String name=rs.getString(2);
String birth=rs.getString(3);
String height=rs.getString(4);
chuang.Text1.setText(chuang.number);
chuang.Text2.setText(chuang.name);
chuang.Text3.setText(chuang.birthday);
chuang.Text4.setText(chuang.height);
con.close(); }
catch(SQLException e2) {}
}
else
if(e.getSource()==chuang.lastBtn){
try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");}
catch(ClassNotFoundException e1){}
try { con=DriverManager.getConnection("jdbc:sqlsever://127.0.0.1:1433;DatabaseName=master","sa","QMPH6-VDV79-CRBCX-HQ32P-F84B3");
sql=con.createStatement
(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=sql.executeQuery("SELECT * FROM message");
rs.last();
int i=rs.getRow();
rs.absolute(i); //游标移到这一行
String number=rs.getString(1);
String name=rs.getString(2);
String birth=rs.getString(3);
String height=rs.getString(4);
chuang.Text1.setText(chuang.number);
chuang.Text2.setText(chuang.name);
chuang.Text3.setText(chuang.birthday);
chuang.Text4.setText(chuang.height);
con.close(); }
catch(SQLException e2) {}
}
}
}