⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.java

📁 jbuilder开发的多用户通讯系统。jbuilder开发的多用户通讯系统
💻 JAVA
字号:
package addresssys;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.dx.sql.dataset.*;import com.borland.dx.dataset.*;/** * <p>Title: 多用户通讯系统</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2007</p> * <p>Company: </p> * @author 李宁 * @version 1.0 */public class MainFrame extends JFrame {  JPanel contentPane;  JRadioButton jRadioButton1 = new JRadioButton();  JRadioButton jRadioButton2 = new JRadioButton();  JRadioButton jRadioButton3 = new JRadioButton();  JTextField jT1 = new JTextField();  JPasswordField jP1 = new JPasswordField();  JLabel jL1 = new JLabel();  JLabel jL2 = new JLabel();  JButton jButton1 = new JButton();  JButton jButton2 = new JButton();  ButtonGroup buttonGroup1 = new ButtonGroup();  Database database1 = new Database();  QueryDataSet queryDataSet1 = new QueryDataSet();  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();    jRadioButton1.setFont(new java.awt.Font("Dialog", 0, 16));    jRadioButton1.setSelected(true);    jRadioButton1.setText("登录");    jRadioButton1.setBounds(new Rectangle(17, 27, 94, 15));    contentPane.setLayout(null);    this.setSize(new Dimension(455, 390));    this.setTitle("Frame Title");    jRadioButton2.setFont(new java.awt.Font("Dialog", 0, 16));    jRadioButton2.setText("修改密码 ");    jRadioButton2.setBounds(new Rectangle(150, 24, 112, 18));    jRadioButton3.setFont(new java.awt.Font("Dialog", 0, 16));    jRadioButton3.setText("注册");    jRadioButton3.setBounds(new Rectangle(289, 21, 137, 20));    jT1.setFont(new java.awt.Font("Dialog", 0, 16));    jT1.setText("");    jT1.setBounds(new Rectangle(196, 80, 212, 37));    jP1.setFont(new java.awt.Font("Dialog", 0, 16));    jP1.setText("");    jP1.setBounds(new Rectangle(196, 139, 212, 37));    jL1.setFont(new java.awt.Font("Dialog", 0, 16));    jL1.setText("用户名:");    jL1.setBounds(new Rectangle(25, 72, 137, 41));    jL2.setFont(new java.awt.Font("Dialog", 0, 16));    jL2.setText("密码:");    jL2.setBounds(new Rectangle(22, 138, 137, 41));    jButton1.setBounds(new Rectangle(24, 221, 172, 66));    jButton1.setFont(new java.awt.Font("Dialog", 0, 16));    jButton1.setText("确定");    jButton1.addActionListener(new MainFrame_jButton1_actionAdapter(this));    jButton2.setBounds(new Rectangle(209, 221, 172, 66));    jButton2.setFont(new java.awt.Font("Dialog", 0, 16));    jButton2.setText("退出");    jButton2.addActionListener(new MainFrame_jButton2_actionAdapter(this));    database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=addresslist", "sa", "sa", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver"));    queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select * from address_users", null, true, Load.ALL));    column1.setColumnName("UserName");    column1.setDataType(com.borland.dx.dataset.Variant.STRING);    column1.setPreferredOrdinal(0);    column1.setServerColumnName("NewColumn1");    column1.setSqlType(0);    column2.setColumnName("Password");    column2.setDataType(com.borland.dx.dataset.Variant.STRING);    column2.setPreferredOrdinal(1);    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));    contentPane.add(jRadioButton1, null);    contentPane.add(jRadioButton2, null);    contentPane.add(jRadioButton3, null);    contentPane.add(jT1, null);    contentPane.add(jP1, null);    contentPane.add(jL1, null);    contentPane.add(jL2, 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 username = jT1.getText().trim();     String password = new String(this.jP1.getPassword());     //输入框有效性判断     if(username.equals("")||password.equals("")){         JOptionPane.showMessageDialog(this,"请输入用户名和密码!");         return;     }     //打开并运行查询,得到结果集     this.queryDataSet1.open();     if(this.jRadioButton3.isSelected()){        do{//排除同名用户注册            if(this.queryDataSet1.getString("username").equals(username)){              JOptionPane.showMessageDialog(this,"该用户已经存在,请重新输入!");              jT1.setText("");              jP1.setText("");              return;            }        }while(this.queryDataSet1.next());        /*用来完成用户的注册*/        //移到记录集的最后        this.queryDataSet1.last();        //在记录集的最后插入一行记录        this.queryDataSet1.insertRow(false);        //设置插入记录的username字段        this.queryDataSet1.setString("username",username);        //设置插入记录的怕ssword字段        this.queryDataSet1.setString("password",password);        //将对记录集的修改保存到数据库中        database1.saveChanges(queryDataSet1);         JOptionPane.showMessageDialog(this,"成功注册用户!");     }     else{       //设置参数对象字段值       this.parameterRow1.setString("username",username);       this.parameterRow1.setString("password",password);       this.queryDataSet2.open();       if(this.jRadioButton1.isSelected()){           AddrMaintainDialog addr = new  AddrMaintainDialog(this,"通讯录维护",false,database1,this.queryDataSet2);           addr.setLocation(280,280);           addr.setSize(350,320);           addr.show();       }       else if(this.jRadioButton2.isSelected()){          PasswordModifyDialog passwordmodify = new PasswordModifyDialog(this,"用户密码修改",false,database1,this.queryDataSet2) ;          passwordmodify.setLocation(280,280);          passwordmodify.setSize(350,320);          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 + -