java吧 关注:1,228,045贴子:12,686,365
  • 0回复贴,共1

取不到jtextfield里的值怎么办

只看楼主收藏回复

我在输出时专门验证了jtf1.getText();结果取不到jtextfield里的值,输出不出来,咋办
package 管理员具体功能实现;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import 对象.manager;
import 界面类.managerframe;
import java.awt.*;
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;
public class deleteuser extends JFrame implements ActionListener{
JLabel jl1;
JButton **1,**2;
JTextField jtf1;
static Connection con = null;
Statement sm = null;
private int i;
public static void main(String[] args) {
// TODO 自动生成的方法存根
deleteuser d=new deleteuser ();
}
public deleteuser (){
JLabel jl1=new JLabel("用户名");
JButton **1=new JButton("删除");
**1.addActionListener(this);
JButton **2=new JButton("取消");
**2.addActionListener(this);
JTextField jtf1=new JTextField();
this.setLayout(new GridLayout(2,2));
this.add(jl1);
this.add(jtf1);
this.add(**1);
this.add(**2);
this.setSize(525,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setTitle("删除读者界面"); //设置标题
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("删除")){
String UserName = "sa";
String Password = "sa";
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String Url = "jdbc:sqlserver://127.0.0.1;database=book3";
try {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
System.out.println("数据库驱动加载成功");
con=DriverManager.getConnection(Url,UserName,Password);
} catch (SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
try {
if(!con.isClosed()){
System.out.println("数据库连接成功");
}
} catch (SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
Statement sm = null;
try {
sm = con.createStatement();
} catch (SQLException e2) {
// TODO 自动生成的 catch 块
e2.printStackTrace();
}
ResultSet rs = null;
try {
JTextField jtf1=new JTextField();
rs = sm.executeQuery("select creditrating from creditrating where User2_name='jtf1.getText()'");
System.out.println(jtf1.getText());
} catch (SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
try {
while(rs.next()){
String a1=rs.getString("creditrating");
System.out.println(2);
System.out.println(a1);
System.out.println(3);
}
} catch (SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
//if(i==1){
//System.out.println("修改成功");
//}
}
if(e.getActionCommand().equals("取消")){
new managerframe();
}
}
}


1楼2018-03-28 19:58回复