📄 stzcdialog.java~13~
字号:
package studentgl;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class stzcDialog extends JDialog { JPanel panel1 = new JPanel(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JLabel jLabel4 = new JLabel(); JTextField jTextField1 = new JTextField(); JTextField jTextField2 = new JTextField(); JTextField jTextField3 = new JTextField(); JComboBox jComboBox1 = new JComboBox(); JLabel jLabel5 = new JLabel(); JPasswordField jPasswordField1 = new JPasswordField(); JLabel jLabel6 = new JLabel(); JLabel jLabel7 = new JLabel(); JLabel jLabel8 = new JLabel(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); private Connection con; private mainFrame Frame1; private Statement stmt; JTextField jTextField4 = new JTextField(); JLabel jLabel9 = new JLabel(); JLabel jLabel10 = new JLabel(); JPasswordField jPasswordField2 = new JPasswordField(); public stzcDialog(mainFrame frame, String title, boolean modal) { super(frame, title, modal); this.setLocation(309,239); Frame1=frame; try { jbInit(); pack(); } catch(Exception ex) { ex.printStackTrace(); } } public stzcDialog() { this(null, "", false); } private void jbInit() throws Exception { panel1.setLayout(null); jLabel1.setFont(new java.awt.Font("Serif", 0, 16)); jLabel1.setForeground(SystemColor.textHighlight); jLabel1.setHorizontalAlignment(SwingConstants.CENTER); jLabel1.setText("学号:"); jLabel1.setBounds(new Rectangle(16, 16, 65, 25)); jLabel2.setBounds(new Rectangle(193, 18, 65, 25)); jLabel2.setText("姓名:"); jLabel2.setHorizontalAlignment(SwingConstants.CENTER); jLabel2.setForeground(SystemColor.textHighlight); jLabel2.setFont(new java.awt.Font("Serif", 0, 16)); jLabel3.setBounds(new Rectangle(17, 68, 65, 25)); jLabel3.setText("性别:"); jLabel3.setHorizontalAlignment(SwingConstants.CENTER); jLabel3.setForeground(SystemColor.textHighlight); jLabel3.setFont(new java.awt.Font("Serif", 0, 16)); jLabel4.setBounds(new Rectangle(195, 72, 65, 25)); jLabel4.setText("班级:"); jLabel4.setHorizontalAlignment(SwingConstants.CENTER); jLabel4.setForeground(SystemColor.textHighlight); jLabel4.setFont(new java.awt.Font("Serif", 0, 16)); jTextField1.setFont(new java.awt.Font("Serif", 0, 12)); jTextField1.setText(""); jTextField1.setBounds(new Rectangle(69, 18, 98, 24)); jTextField2.setBounds(new Rectangle(248, 19, 98, 24)); jTextField2.setFont(new java.awt.Font("Serif", 0, 12)); jTextField2.setText(""); jTextField3.setFont(new java.awt.Font("Serif", 0, 12)); jTextField3.setText(""); jTextField3.setBounds(new Rectangle(249, 69, 98, 24)); /* Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); String url = "jdbc:microsoft:sqlserver://ISSAC:1433;DatabaseName=StudentGL"; String username = "sa"; String password = "123456"; Connection con = DriverManager.getConnection(url,username,password); Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); Connection con = connect.getconn(); Statement stmt1 = con.createStatement(); ResultSet strs1 = stmt1.executeQuery("select distinct Sex from StudentInfo"); jComboBox1.addItem(""); while(strs1.next()){ jComboBox1.addItem(strs1.getString("Sex")); } con.close(); */ jComboBox1.setFont(new java.awt.Font("Dialog", 0, 12)); jComboBox1.setBounds(new Rectangle(72, 69, 101, 24)); jComboBox1.addItem(""); jComboBox1.addItem("男"); jComboBox1.addItem("女"); jLabel5.setFont(new java.awt.Font("Serif", 0, 16)); jLabel5.setForeground(Color.red); jLabel5.setHorizontalAlignment(SwingConstants.CENTER); jLabel5.setText("密码:"); jLabel5.setBounds(new Rectangle(13, 113, 71, 28)); jPasswordField1.setText(""); jPasswordField1.setBounds(new Rectangle(66, 115, 106, 26)); jLabel6.setFont(new java.awt.Font("Serif", 0, 16)); jLabel6.setForeground(Color.red); jLabel6.setText("*"); jLabel6.setBounds(new Rectangle(172, 21, 25, 16)); jLabel7.setBounds(new Rectangle(355, 23, 25, 16)); jLabel7.setText("*"); jLabel7.setForeground(Color.red); jLabel7.setFont(new java.awt.Font("Serif", 0, 16)); jLabel8.setBounds(new Rectangle(173, 73, 25, 16)); jLabel8.setText("*"); jLabel8.setForeground(Color.red); jLabel8.setFont(new java.awt.Font("Serif", 0, 16)); jButton1.setBounds(new Rectangle(61, 227, 73, 25)); jButton1.setFont(new java.awt.Font("Serif", 0, 12)); jButton1.setForeground(Color.red); jButton1.setText("确定"); jButton1.addActionListener(new stzcDialog_jButton1_actionAdapter(this)); jButton2.setBounds(new Rectangle(273, 228, 73, 25)); jButton2.setFont(new java.awt.Font("Serif", 0, 12)); jButton2.setForeground(Color.orange); jButton2.setHorizontalAlignment(SwingConstants.CENTER); jButton2.setText("重设"); jButton2.addActionListener(new stzcDialog_jButton2_actionAdapter(this)); jTextField4.setBackground(Color.lightGray); jTextField4.setFont(new java.awt.Font("Serif", 0, 12)); jTextField4.setForeground(Color.red); jTextField4.setText("带星号为必填!"); jTextField4.setBounds(new Rectangle(143, 195, 223, 25)); jLabel9.setText("注:"); jLabel9.setFont(new java.awt.Font("Serif", 0, 16)); jLabel9.setForeground(Color.red); jLabel9.setHorizontalAlignment(SwingConstants.CENTER); jLabel9.setText("提示信息:"); jLabel9.setBounds(new Rectangle(33, 199, 80, 18)); jLabel10.setBounds(new Rectangle(181, 113, 105, 28)); jLabel10.setText("再输入密码:"); jLabel10.setHorizontalAlignment(SwingConstants.CENTER); jLabel10.setForeground(Color.red); jLabel10.setFont(new java.awt.Font("Serif", 0, 16)); jPasswordField2.setBounds(new Rectangle(274, 116, 106, 26)); jPasswordField2.setText(""); panel1.add(jLabel1, null); panel1.add(jLabel3, null); panel1.add(jTextField1, null); panel1.add(jTextField2, null); panel1.add(jLabel2, null); panel1.add(jComboBox1, null); panel1.add(jLabel6, null); panel1.add(jLabel7, null); panel1.add(jLabel4, null); panel1.add(jTextField3, null); panel1.add(jLabel8, null); panel1.add(jButton1, null); panel1.add(jButton2, null); panel1.add(jLabel9, null); panel1.add(jTextField4, null); panel1.add(jLabel10, null); panel1.add(jLabel5, null); panel1.add(jPasswordField1, null); panel1.add(jPasswordField2, null); this.getContentPane().add(panel1, BorderLayout.CENTER); con = connect.getconn(); } void jButton1_actionPerformed(ActionEvent e) { try { con=connect.getconn(); Statement getInsert=con.createStatement(); stmt=con.createStatement(); String stid=jTextField1.getText().trim(); String xm=jTextField2.getText().trim(); String bj=jTextField3.getText().trim(); String sex=jComboBox1.getSelectedItem().toString(); String pwd= jPasswordField1.getText(); String pwd1=jPasswordField1.getText(); int rowcount=0; String loginQuery="select * from StudentInfo where stID="+stid+""; ResultSet rs = stmt.executeQuery(loginQuery); while (rs.next()){ rowcount++; }if(rowcount==1){ jTextField4.setText("学号已经存在,请重新输入!"); } else if((rowcount==0)&&(pwd.equals(pwd1))){ String insert="insert into StudentInfo values('"+stid+"','"+pwd+"','"+xm+"','"+sex+"','"+bj+"')"; getInsert.executeUpdate(insert); Frame1.login=true; this.hide(); return; } else{ jTextField4.setText("两次密码不同,请重新输入!"); } con.close(); } catch(SQLException ex){ System.out.print("系统或者输进数据错误!");}} void jButton2_actionPerformed(ActionEvent e) { jTextField1.setText(""); jTextField2.setText(""); jTextField3.setText(""); jTextField4.setText("带星号为必填!"); jPasswordField1.setText(""); jComboBox1.setSelectedIndex(0); } }class stzcDialog_jButton1_actionAdapter implements java.awt.event.ActionListener { stzcDialog adaptee; stzcDialog_jButton1_actionAdapter(stzcDialog adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}class stzcDialog_jButton2_actionAdapter implements java.awt.event.ActionListener { stzcDialog adaptee; stzcDialog_jButton2_actionAdapter(stzcDialog adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton2_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -