📄 mainframe.java~13~
字号:
package tongxinbu;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.dx.sql.dataset.*;
import com.borland.dx.dataset.*;
public class MainFrame extends JFrame {
JPanel contentPane;
JRadioButton jRadioButton1 = new JRadioButton();
JRadioButton jRadioButton2 = new JRadioButton();
JRadioButton jRadioButton3 = new JRadioButton();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JTextField jTextField1 = new JTextField();
JPasswordField jPasswordField1 = new JPasswordField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
ButtonGroup buttonGroup1 = new ButtonGroup();
Database database1 = new Database();
QueryDataSet queryDataSet1 = new QueryDataSet();
boolean status=false;
String pass="";
//Construct the frame
public MainFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jRadioButton1.setFont(new java.awt.Font("Dialog", 0, 16));
jRadioButton1.setDebugGraphicsOptions(0);
jRadioButton1.setText("登录");
jRadioButton1.setBounds(new Rectangle(40, 41, 66, 25));
contentPane.setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("多用户通讯簿系统");
jRadioButton2.setBounds(new Rectangle(139, 41, 90, 25));
jRadioButton2.setText("修改密码");
jRadioButton2.setFont(new java.awt.Font("Dialog", 0, 16));
jRadioButton3.setBounds(new Rectangle(261, 41, 66, 25));
jRadioButton3.setText("注册");
jRadioButton3.setFont(new java.awt.Font("Dialog", 0, 16));
jRadioButton3.setSelected(true);
jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));
jLabel1.setText("用户名");
jLabel1.setBounds(new Rectangle(40, 93, 51, 29));
jLabel2.setBounds(new Rectangle(40, 148, 51, 29));
jLabel2.setText("密 码");
jLabel2.setFont(new java.awt.Font("Dialog", 0, 16));
jTextField1.setFont(new java.awt.Font("Dialog", 0, 16));
jTextField1.setText("");
jTextField1.setBounds(new Rectangle(137, 91, 165, 34));
jPasswordField1.setFont(new java.awt.Font("Dialog", 0, 16));
jPasswordField1.setText("");
jPasswordField1.setBounds(new Rectangle(137, 142, 165, 34));
jButton1.setBounds(new Rectangle(77, 212, 86, 35));
jButton1.setFont(new java.awt.Font("Dialog", 0, 16));
jButton1.setFocusPainted(true);
jButton1.setText("确定");
jButton1.addActionListener(new MainFrame_jButton1_actionAdapter(this));
jButton2.setText("退出");
jButton2.setFocusPainted(true);
jButton2.setFont(new java.awt.Font("Dialog", 0, 16));
jButton2.setBounds(new Rectangle(190, 210, 86, 35));
database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:microsoft:sqlserver://127.0.0.1:1433;DataBaseName=addresslist", "sa", "", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver"));
database1.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED);
database1.setDatabaseName("");
queryDataSet1.setMetaDataUpdate(MetaDataUpdate.ALL);
// queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select * from address_users where username=\'a\'", null, true, Load.ALL));
contentPane.add(jRadioButton1, null);
contentPane.add(jRadioButton2, null);
contentPane.add(jRadioButton3, null);
contentPane.add(jLabel1, null);
contentPane.add(jLabel2, null);
contentPane.add(jTextField1, null);
contentPane.add(jPasswordField1, null);
contentPane.add(jButton2, null);
contentPane.add(jButton1, null);
buttonGroup1.add(jRadioButton1);
buttonGroup1.add(jRadioButton2);
buttonGroup1.add(jRadioButton3);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jButton1_actionPerformed(ActionEvent e) {
String user=jTextField1.getText().trim();
String pass=jPasswordField1.getText().trim();
queryDataSet1.close();//先关闭
queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select * from address_users where username=\'"
+user+"\'", null, true, Load.ALL));
queryDataSet1.executeQuery();//再执行
if(jRadioButton1.isSelected()){
if (queryDataSet1.rowCount() > 0) {
SucFrame s=new SucFrame();
s.setSize(400,300);
s.show();
}else{
JOptionPane.showMessageDialog(this, "该用户不存在,请重新输入");
}
}
if(jRadioButton2.isSelected()){
if (queryDataSet1.rowCount() > 0) {
EditDialog s = new EditDialog(this,"密码修改",true);
s.setSize(400, 300);
s.show();
if(status){
queryDataSet1.setString("password",this.pass);
database1.saveChanges(queryDataSet1);
}
}else{
JOptionPane.showMessageDialog(this, "该用户不存在,请重新输入");
}
}
if(jRadioButton3.isSelected()){
if (queryDataSet1.rowCount() > 0) {
JOptionPane.showMessageDialog(this, "该用户已经存在,请重新输入");
jTextField1.setText("");
jPasswordField1.setText("");
return;
}
else {
queryDataSet1.last();
queryDataSet1.insertRow(true);
queryDataSet1.setString("userName", user);
queryDataSet1.setString("Password", pass);
database1.saveChanges(queryDataSet1);
JOptionPane.showMessageDialog(this, "成功注册");
}
}
}
}
class MainFrame_jButton1_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;
MainFrame_jButton1_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -