📄 loadframe.java
字号:
/*
* LoadFrame.java
*
* Created on 2007年7月4日, 上午8:22
*/
package t;
/**
*
* @author Administrator
*/
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.*;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class LoadFrame extends javax.swing.JFrame {
/** Creates new form LoadFrame */
public LoadFrame() {
initCon();
initComponents();
this.setLoc(this);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
yonghuming = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
mima = new javax.swing.JPasswordField();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("\u673a\u7968\u9884\u5b9a\u7cfb\u7edf");
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jLabel1.setFont(new java.awt.Font("宋体", 1, 18));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("\u673a\u7968\u9884\u5b9a\u7cfb\u7edf");
jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jLabel2.setText("\u7528\u6237\u540d");
jLabel3.setText("\u5bc6\u7801");
jButton1.setText("\u767b\u9646");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("\u53d6\u6d88");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
mima.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mimaActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(37, 37, 37)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel2)
.add(jLabel3)
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton1)))
.add(10, 10, 10)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(org.jdesktop.layout.GroupLayout.LEADING, mima)
.add(org.jdesktop.layout.GroupLayout.LEADING, yonghuming, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))
.add(jButton2)))
.add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 204, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(89, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 38, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(40, 40, 40)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(yonghuming, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel2))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 43, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(mima, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel3))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 28, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton2)
.add(jButton1))
.add(22, 22, 22))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO 将在此处添加您的处理代码:
System.exit(0);
}//GEN-LAST:event_jButton2ActionPerformed
private void mimaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mimaActionPerformed
// TODO 将在此处添加您的处理代码:
String name = this.yonghuming.getText();
String yonghumima = new String(this.mima.getPassword());
if(name.equals("")) {
JOptionPane.showMessageDialog(this,"用户名不能为空","警告 ",JOptionPane.INFORMATION_MESSAGE);
}else {
try {
String selecturl = "select * from 员工信息表 where username = '"+name+"' and password = '"+yonghumima+"'";
rs = stmt.executeQuery(selecturl);
if(rs.next()) {
this.dispose();
new Main1JFrame().setVisible(true);
} else {
JOptionPane.showMessageDialog(this,"用户名或密码错误","警告 ",JOptionPane.INFORMATION_MESSAGE);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}//GEN-LAST:event_mimaActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO 将在此处添加您的处理代码:
String name = this.yonghuming.getText();
String yonghumima = new String(this.mima.getPassword());
if(name.equals("")) {
JOptionPane.showMessageDialog(this,"用户名不能为空","警告 ",JOptionPane.INFORMATION_MESSAGE);
}else {
try {
String selecturl = "select * from 员工信息表 where username = '"+name+"' and password = '"+yonghumima+"'";
rs = stmt.executeQuery(selecturl);
if(rs.next()) {
this.dispose();
new Main1JFrame().setVisible(true);
} else {
JOptionPane.showMessageDialog(this,"用户名或密码错误","警告 ",JOptionPane.INFORMATION_MESSAGE);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LoadFrame().setVisible(true);
}
});
}
public void initCon() {
try {
con =new AccessConnection().getcon();
stmt = con.createStatement();
}catch(SQLException e) {
e.printStackTrace();
}
}
class AccessConnection {
public AccessConnection ()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public Connection getcon() throws SQLException{
return DriverManager.getConnection("jdbc:odbc:jipiaodatebase","", "");
}
}
public static void setLoc(java.awt.Window jf){
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = jf.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
jf.setLocation((screenSize.width - frameSize.width)/ 2, (screenSize.height- frameSize.height) /2);
}
private Connection con;
private Statement stmt;
private ResultSet rs;
// 变量声明 - 不进行修改//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPasswordField mima;
private javax.swing.JTextField yonghuming;
// 变量声明结束//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -