📄 mainframe.java~33~
字号:
package addresssys;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.jbcl.layout.*;import com.borland.dx.sql.dataset.*;import com.borland.dx.dataset.*;public class MainFrame extends JFrame { JPanel contentPane; XYLayout xYLayout1 = new XYLayout(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JTextField jTextField1 = new JTextField(); JPasswordField jPasswordField1 = new JPasswordField(); JButton jButton1 = new JButton(); Database database1 = new Database(); QueryDataSet queryDataSet1 = new QueryDataSet(); JRadioButton jRadioButton1 = new JRadioButton(); JRadioButton jRadioButton2 = new JRadioButton(); JRadioButton jRadioButton3 = new JRadioButton(); JButton jButton2 = new JButton(); ButtonGroup buttonGroup1 = new ButtonGroup(); ParameterRow parameterRow1 = new ParameterRow(); Column column1 = new Column(); Column column2 = new Column(); QueryDataSet queryDataSet2 = new QueryDataSet(); //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(); jLabel1.setFont(new java.awt.Font("Dialog", 0, 14)); jLabel1.setText("用户名:"); contentPane.setLayout(xYLayout1); this.setSize(new Dimension(300, 300)); this.setTitle("多用户通讯簙系统"); jLabel2.setFont(new java.awt.Font("Dialog", 0, 14)); jLabel2.setText("密 码:"); jTextField1.setFont(new java.awt.Font("Dialog", 0, 14)); jTextField1.setText(""); jPasswordField1.setFont(new java.awt.Font("Dialog", 0, 14)); jPasswordField1.setText(""); jButton1.setFont(new java.awt.Font("Dialog", 0, 14)); jButton1.setText("确 定"); jButton1.addActionListener(new MainFrame_jButton1_actionAdapter(this)); contentPane.setFont(new java.awt.Font("Dialog", 0, 14)); database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=addresslist", "sa", "", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver")); jRadioButton1.setFont(new java.awt.Font("Dialog", 0, 14)); jRadioButton1.setSelected(true); jRadioButton1.setText("登录"); jRadioButton2.setFont(new java.awt.Font("Dialog", 0, 14)); jRadioButton2.setText("修改密码"); jRadioButton3.setFont(new java.awt.Font("Dialog", 0, 14)); jRadioButton3.setText("注册"); jButton2.setText("退 出"); jButton2.addActionListener(new MainFrame_jButton2_actionAdapter(this)); jButton2.setFont(new java.awt.Font("Dialog", 0, 14)); column1.setColumnName("UserName"); column1.setDataType(com.borland.dx.dataset.Variant.STRING); column1.setDefault(""); column1.setServerColumnName("NewColumn1"); column1.setSqlType(0); column2.setColumnName("Password"); column2.setDataType(com.borland.dx.dataset.Variant.STRING); column2.setDefault(""); column2.setServerColumnName("NewColumn2"); column2.setSqlType(0); parameterRow1.setColumns(new Column[] {column1, column2}); queryDataSet2.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select * from address_users where UserName=:UserName and Password=:Password", parameterRow1, true, Load.ALL)); queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select * from address_users", null, true, Load.ALL)); contentPane.add(jLabel2, new XYConstraints(52, 131, 68, 29)); contentPane.add(jPasswordField1, new XYConstraints(131, 131, 113, 30)); contentPane.add(jLabel1, new XYConstraints(51, 71, 68, 29)); contentPane.add(jTextField1, new XYConstraints(129, 71, 113, 30)); contentPane.add(jRadioButton1, new XYConstraints(46, 30, -1, 20)); contentPane.add(jRadioButton3, new XYConstraints(213, 30, -1, 20)); contentPane.add(jRadioButton2, new XYConstraints(118, 30, 87, 20)); contentPane.add(jButton2, new XYConstraints(160, 193, 74, 30)); contentPane.add(jButton1, new XYConstraints(59, 193, 74, 30)); 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 userName=jTextField1.getText().trim(); String password=new String(jPasswordField1.getPassword()); if(jRadioButton3.isSelected()){ queryDataSet1.open(); //打开并运行查询,得到结果集 queryDataSet1.last(); //移到记录集的最后 queryDataSet1.insertRow(false);//在记录集的最后插入一行记录 queryDataSet1.setString("UserName",userName);//设置插入记录的UseName字段值 queryDataSet1.setString("Password",password);//设置插入记录的Password字段值 database1.saveChanges(queryDataSet1);//将对记录集的修改保存到数据库中 JOptionPane.showMessageDialog(this,"成功注册用户"); } else { //①此处将插入登录与修改密码处理代码 parameterRow1.setString("UserName",userName);//设置参数对象的UserName字段的值 parameterRow1.setString("Password",password);//设置参数对象Password字段的值 queryDataSet2.open(); if(queryDataSet2.rowCount()>0){//用户存在 if(jRadioButton1.isSelected()){ //②此处将插入转入通讯录维护界面的代码 AddrMaintainDialog addrMaintain=new AddrMaintainDialog(this,"通讯录维护",false,queryDataSet2); addrMaintain.show(); } else if(jRadioButton2.isSelected()){ PasswordModifyDialog passwordModify=new PasswordModifyDialog(this,"用户密码修改",false,database1,queryDataSet2); passwordModify.show(); } } } } void jButton2_actionPerformed(ActionEvent e) { System.exit(0); }}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); }}class MainFrame_jButton2_actionAdapter implements java.awt.event.ActionListener { MainFrame adaptee; MainFrame_jButton2_actionAdapter(MainFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton2_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -