📄 mxg.java
字号:
package atm;
//import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JPanel;
import javax.swing.JFrame;
import oo.Sql;
//import java.awt.Dimension;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
public class MXG extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel jPanel = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JTextField jTextField = null;
private JPasswordField jPasswordField = null;
private JPasswordField jPasswordField1 = null;
private JButton jButton = null;
private JButton jButton1 = null;
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
gridBagConstraints7.gridx = 1;
gridBagConstraints7.gridy = 4;
GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
gridBagConstraints6.gridx = 1;
gridBagConstraints6.gridy = 3;
GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
gridBagConstraints5.fill = GridBagConstraints.VERTICAL;
gridBagConstraints5.gridy = 2;
gridBagConstraints5.weightx = 1.0;
gridBagConstraints5.gridx = 1;
GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
gridBagConstraints4.fill = GridBagConstraints.VERTICAL;
gridBagConstraints4.gridy = 1;
gridBagConstraints4.weightx = 1.0;
gridBagConstraints4.gridx = 1;
GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
gridBagConstraints3.fill = GridBagConstraints.VERTICAL;
gridBagConstraints3.gridy = 0;
gridBagConstraints3.weightx = 1.0;
gridBagConstraints3.gridx = 1;
GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
gridBagConstraints2.gridx = 0;
gridBagConstraints2.gridy = 2;
jLabel2 = new JLabel();
jLabel2.setText("新密码:");
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.gridy = 1;
jLabel1 = new JLabel();
jLabel1.setText("旧密码:");
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
jLabel = new JLabel();
jLabel.setText("管理员:");
jPanel = new JPanel();
jPanel.setLayout(new GridBagLayout());
jPanel.add(jLabel, gridBagConstraints);
jPanel.add(jLabel1, gridBagConstraints1);
jPanel.add(jLabel2, gridBagConstraints2);
jPanel.add(getJTextField(), gridBagConstraints3);
jPanel.add(getJPasswordField(), gridBagConstraints4);
jPanel.add(getJPasswordField1(), gridBagConstraints5);
jPanel.add(getJButton(), gridBagConstraints6);
jPanel.add(getJButton1(), gridBagConstraints7);
}
return jPanel;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setColumns(8);
}
return jTextField;
}
/**
* This method initializes jPasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setColumns(8);
}
return jPasswordField;
}
/**
* This method initializes jPasswordField1
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField1() {
if (jPasswordField1 == null) {
jPasswordField1 = new JPasswordField();
jPasswordField1.setColumns(8);
}
return jPasswordField1;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("确认修改");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
quer();
}
});
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("返回");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
close();
}
});
}
return jButton1;
}
public void close(){
this.setVisible(false);
}
/**
* @param args
*/
/*public static void main(String[] args) {
// TODO 自动生成方法存根
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MXG thisClass = new MXG();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public MXG() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(325, 241);
this.setContentPane(getJContentPane());
this.setTitle("密码修改");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJPanel(), BorderLayout.CENTER);
}
return jContentPane;
}
public void quer(){
//栏位判断
if (jPasswordField.getPassword().equals("") || jPasswordField1.getPassword().equals("") ||
jTextField.getText().equals("")) {
javax.swing.JOptionPane.showMessageDialog(this, "任何一栏不能为空!");
} else {
Sql dbc = new Sql();
dbc.getConn();
boolean success = false;
ResultSet rs = dbc.executeQuery("SELECT * FROM admin");
//查询并判断原始信息是否匹配
try {
while (rs.next()) {
if (jTextField.getText().equals(rs.getString("user")) || jPasswordField.getPassword().equals(rs.getString("pass"))) {
success = true;
}
}
//匹配则容许修改
if (success) {
if (dbc.executeUpdateSQL("UPDATE admin SET pass = '" +String.valueOf(jPasswordField1.getPassword())+ "' where user='"+UserFrm.user+"'")) {
javax.swing.JOptionPane.showMessageDialog(this,"密码修改成功。");
} else {
javax.swing.JOptionPane.showMessageDialog(this, "密码修改失败,请重试。");
}
} else {
javax.swing.JOptionPane.showMessageDialog(this,"用户名或原始密码错误!请重新确认!");
return;
}
} catch (SQLException ex) {
javax.swing.JOptionPane.showMessageDialog(this,ex.getMessage().toString());
return;
}
}
}
} // @jve:decl-index=0:visual-constraint="10,10"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -