📄 find.java
字号:
package cn.hebut;
import javax.swing.JPanel;
import java.awt.Frame;
import java.awt.BorderLayout;
import javax.swing.JDialog;
import java.awt.Dimension;
import javax.swing.border.SoftBevelBorder;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
public class Find extends JDialog {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JTextField jfnum = null;
private JPasswordField jfpassword = null;
private JTextField jfyuer = null;
private JButton jfind = null;
private JButton jcancel = null;
private JLabel jLabel3 = null;
/**
* @param owner
*/
public Find( ) {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(493, 348);
this.setTitle("余额查询");
this.setContentPane(getJContentPane());
this.setModal(true);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(339, 47, 89, 24));
jLabel3.setText("必添5位数字");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(38, 185, 64, 31));
jLabel2.setText("余额:");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(38, 113, 64, 31));
jLabel1.setText("密码:");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(38, 45, 64, 31));
jLabel.setText("卡号:");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
jContentPane.add(jLabel, null);
jContentPane.add(jLabel1, null);
jContentPane.add(jLabel2, null);
jContentPane.add(getJfnum(), null);
jContentPane.add(getJfpassword(), null);
jContentPane.add(getJfyuer(), null);
jContentPane.add(getJfind(), null);
jContentPane.add(getJcancel(), null);
jContentPane.add(jLabel3, null);
}
return jContentPane;
}
/**
* This method initializes jfnum
*
* @return javax.swing.JTextField
*/
private JTextField getJfnum() {
if (jfnum == null) {
jfnum = new JTextField();
jfnum.setBounds(new Rectangle(142, 44, 163, 28));
}
return jfnum;
}
/**
* This method initializes jfpassword
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJfpassword() {
if (jfpassword == null) {
jfpassword = new JPasswordField();
jfpassword.setBounds(new Rectangle(142, 113, 159, 28));
}
return jfpassword;
}
/**
* This method initializes jfyuer
*
* @return javax.swing.JTextField
*/
private JTextField getJfyuer() {
if (jfyuer == null) {
jfyuer = new JTextField();
jfyuer.setBounds(new Rectangle(143, 186, 153, 28));
jfyuer.setEditable(false);
}
return jfyuer;
}
/**
* This method initializes jfind
*
* @return javax.swing.JButton
*/
private JButton getJfind() {
if (jfind == null) {
jfind = new JButton();
jfind.setBounds(new Rectangle(130, 253, 79, 32));
jfind.setText("查询");
jfind.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
find();//查询函数
}
});
}
return jfind;
}
//查询函数
public void find()
{
String num=jfnum.getText();
if(Mainframe.numValid(num))
{
if(Qukuan.valid(num, jfpassword.getText()))
{
valid(num);
}
else
{
JOptionPane.showMessageDialog(null, "账户不存在或用户密码错误!");
}
}
else
{
JOptionPane.showMessageDialog(null, "请输入5位的数字卡号!");
}
}
// 检查取款用户名和密码并且获得余额
public void valid(String s1)
{
ResultSet rset=null;
Statement stmt=null;
Connection conn=Sql.link();//连接数据库
try {
stmt=conn.createStatement();
rset=stmt.executeQuery("select 余额 from 储户信息 where 账户号='"+s1+"'");
if(rset.next())//验证用户名是否存在
{
String yuer=rset.getString(1);
jfyuer.setText(yuer);
}
else
{
JOptionPane.showMessageDialog(null, "余额不存在!");
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
try {
rset.close();
stmt.close();
conn.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
/**
* This method initializes jcancel
*
* @return javax.swing.JButton
*/
private JButton getJcancel() {
if (jcancel == null) {
jcancel = new JButton();
jcancel.setBounds(new Rectangle(286, 254, 82, 28));
jcancel.setText("取消");
jcancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
Find.this.dispose();
}
});
}
return jcancel;
}
} // @jve:decl-index=0:visual-constraint="10,10"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -