📄 userinpanel.java~10~
字号:
package bar;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;import java.text.*;import java.util.*;import com.borland.dx.sql.dataset.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class userInPanel extends JPanel { JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JLabel jLabel4 = new JLabel(); JComboBox jComboBox1 = new JComboBox(); JTextField jTextField2 = new JTextField(); JTextField jTextField3 = new JTextField(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); JPasswordField jPasswordField1 = new JPasswordField(); barConnect barConnect1=new barConnect(); private Connection con; private Statement queryStmt; private Statement insertStmt; private String loginQuery; private String insertString; public userInPanel(mainFrame mFrame) { try { Frame1 = mFrame; jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { jLabel1.setFont(new java.awt.Font("Serif", 0, 16)); jLabel1.setForeground(new Color(187, 173, 201)); jLabel1.setHorizontalAlignment(SwingConstants.CENTER); jLabel1.setText("机器号码:"); jLabel1.setBounds(new Rectangle(71, 19, 90, 24)); this.setLayout(null); jLabel2.setBounds(new Rectangle(70, 57, 90, 24)); jLabel2.setText("卡 号:"); jLabel2.setHorizontalAlignment(SwingConstants.CENTER); jLabel2.setFont(new java.awt.Font("Serif", 0, 16)); jLabel2.setForeground(new Color(152, 97, 131)); jLabel3.setBounds(new Rectangle(70, 93, 90, 24)); jLabel3.setText("密 码:"); jLabel3.setHorizontalAlignment(SwingConstants.CENTER); jLabel3.setFont(new java.awt.Font("Serif", 0, 16)); jLabel3.setForeground(Color.red); jLabel4.setBounds(new Rectangle(68, 138, 90, 24)); jLabel4.setText("开始时间:"); jLabel4.setHorizontalAlignment(SwingConstants.CENTER); jLabel4.setFont(new java.awt.Font("Serif", 0, 16)); jLabel4.setForeground(Color.magenta); jComboBox1.setBounds(new Rectangle(164, 15, 129, 26)); jTextField2.setText(""); jTextField2.setBounds(new Rectangle(165, 51, 137, 27)); java.util.Date today = new java.util.Date(); SimpleDateFormat HMFromat = new SimpleDateFormat("HH:mm"); String nowTime = HMFromat.format(today); jTextField3.setText(nowTime); jTextField3.setCaretColor(new Color(180, 166, 0)); jTextField3.setBounds(new Rectangle(167, 135, 136, 27)); jButton1.setBounds(new Rectangle(69, 188, 73, 25)); jButton1.setFont(new java.awt.Font("Serif", 0, 12)); jButton1.setForeground(Color.red); jButton1.setContentAreaFilled(true); jButton1.setText("确定"); jButton1.addActionListener(new userInPanel_jButton1_actionAdapter(this)); jButton2.setBounds(new Rectangle(243, 186, 73, 25)); jButton2.setFont(new java.awt.Font("Serif", 0, 12)); jButton2.setForeground(Color.green); jButton2.setText("重设"); jPasswordField1.setCaretColor(new Color(7, 0, 0)); jPasswordField1.setText(""); jPasswordField1.setBounds(new Rectangle(167, 93, 135, 28)); this.add(jLabel4, null); this.add(jLabel3, null); this.add(jLabel2, null); this.add(jLabel1, null); this.add(jPasswordField1, null); this.add(jTextField2, null); this.add(jComboBox1, null); this.add(jTextField3, null); this.add(jButton1, null); this.add(jButton2, null); con = barConnect.getconn(); Statement stmt = con.createStatement(); ResultSet boxRs = stmt.executeQuery("select * from ComputerIDView"); jComboBox1.addItem(""); while(boxRs.next()){ jComboBox1.addItem(boxRs.getString("ComputerID"));//连接并查询需要的数据 } con.close(); } void jButton1_actionPerformed(ActionEvent e) { try{ con=barConnect.getconn(); stmt=con.createStatement(); String passwordtemp=jPasswordField1.getText(); int cardID=Integer.parseInt(jTextField2.getText().trim()); String loginQuery="select * from Card where CardID=" +cardID+" and password = " +passwordtemp; ResultSet rs1 = stmt.executeQuery(loginQuery); if (rs1.next()) {//把用户上机的信息填写到数据库中 insertStmt = con.createStatement(); insertString = "INSERT INTO Event (CardID, ComputerID, BeginTime) VALUES (" + Integer.parseInt(jTextField2.getText().trim()) + ", " + Integer.parseInt(jComboBox1.getSelectedItem().toString()) + ", '" + jTextField3.getText() + ":00')"; int rs2 = insertStmt.executeUpdate(insertString); if(rs2!=1){ jTextField2.setText("上网登记不成功"); } } else { jTextField2.setText("卡号或者密码不对"); } rs1.close(); con.close(); } catch(SQLException ex){ System.out.print("系统错误,请检测数据库"); } welcomePanel welcomePanel2 = new welcomePanel(); Frame1.remove(Frame1.getContentPane()); Frame1.getContentPane().add(welcomePanel2); Frame1.setContentPane(welcomePanel2); Frame1.show(); } private mainFrame Frame1; private Statement stmt;}class userInPanel_jButton1_actionAdapter implements java.awt.event.ActionListener { userInPanel adaptee; userInPanel_jButton1_actionAdapter(userInPanel adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -