📄 startframe.java
字号:
/*
* StartFrame.java
*
* Created on 2007年8月22日, 上午9:52
*/
package org.Adam;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JOptionPane;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import java.lang.String;
import java.util.Vector;
import org.Adam.SplashScreen;
/**
*
* @author Administrator
*/
public class StartFrame extends javax.swing.JFrame {
private static SplashScreen fSplashScreen; // 欢迎屏幕
JOptionPane jOptionPane1=new JOptionPane();
AddStudent aframe = new AddStudent();
ResultSet rs=null;
public String Power=new String();
private String sql;
//this.add(AddStudent);
//StartFrame frame1 = new StartFrame();
/** Creates new form StartFrame */
public StartFrame() {
initComponents();
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setLocationRelativeTo(this);
this.setResizable(false);
}
/** 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();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jPasswordField1 = new javax.swing.JPasswordField();
jLabel3 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("\u5b66\u751f\u4fe1\u606f\u7ba1\u7406\u7cfb\u7edf");
jLabel1.setFont(new java.awt.Font("宋体", 1, 14));
jLabel1.setText("\u7528\u6237\u540d\uff1a");
jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
jTextField1KeyPressed(evt);
}
});
jLabel2.setFont(new java.awt.Font("宋体", 1, 14));
jLabel2.setText("\u5bc6\u7801\uff1a");
jButton1.setText("\u786e\u5b9a");
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);
}
});
jLabel3.setFont(new java.awt.Font("宋体", 1, 18));
jLabel3.setText("\u5f53\u524d\u7528\u6237\u662f\uff1a");
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(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.add(44, 44, 44)
.add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jButton2)
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.add(35, 35, 35)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(jLabel2))
.add(19, 19, 19)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(jPasswordField1)
.add(jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)))))
.addContainerGap(36, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(48, 48, 48)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(75, 75, 75)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(jPasswordField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(52, 52, 52)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 31, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(30, 30, 30)
.add(jLabel3)
.addContainerGap(32, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyPressed
// TODO 将在此处添加您的处理代码:
// String sql="select UserName from PasswordText where ";
StringBuffer Name=new StringBuffer(this.jTextField1.getText());
this.jLabel3.setText("当前用户是:"+Name);
}//GEN-LAST:event_jTextField1KeyPressed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO 将在此处添加您的处理代码:
System.exit(0);
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO 将在此处添加您的处理代码:
String UserName=this.jTextField1.getText();
String UserPassword= new String(jPasswordField1.getPassword());
String pass=null;
DB dB=new DB();
String sql="select UserPassword from PasswordText where UserName='"+UserName+"' and UserPassword='"+UserPassword+"'";
String sql1="select power from PasswordText where UserName='"+UserName+"'";
rs=dB.SelectpassDb(sql);
try {
//pass=rs.getString("UserPassword");//此处的UserPassword是表中对应的列名;
if(rs.next())
{
aframe.setVisible(true);
aframe.setResizable(false);
this.dispose();
}
else
{
StartFrame start=new StartFrame();
String message=new String("对不起,密码或用户名错误!");
String title=new String("错误!");
JOptionPane.showConfirmDialog(start,message,title,JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE,null);
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
rs=dB.SelectpassDb(sql1);
try {
rs.next();
Power=rs.getString("power");
UserInfo.power = Power;
} catch (SQLException ex) {
ex.printStackTrace();
}
//System.out.println(Power);
dB.closeAccessConnection();
/* */
}//GEN-LAST:event_jButton1ActionPerformed
/**/
/**/
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try
{
showSplashScreen(); // 显示软件封面
// 启动应用程序
StartFrame frame = new StartFrame(); // 实例化启动框架
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
// 计算屏幕的大小和 Frame 的大小
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
// 设置 Frame 的大小不超过屏幕的大小
if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; }
if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; }
// 居中显示 Frame
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); // 计算居中显示值
frame.setVisible(true); // 工作窗体可见
EventQueue.invokeLater( new SplashScreenCloser() ); // 关闭软件封面
}
catch(Exception ex)
{
ex.printStackTrace();
System.exit(1);
}
}
private static void showSplashScreen(){
fSplashScreen = new SplashScreen("/images/Splash.jpg"); // 设置封面路径
fSplashScreen.splash(); // 显示封面
}
/**
* @关闭欢迎屏幕 class
*
* 为了以线程安全的方式关闭splash屏幕,
* 用 <foodCode>EventQueue.invokeLater</foodCode>
* 调用该 <foodCode>Runnable</foodCode> ,见377menuFileExit行
*/
private static final class SplashScreenCloser implements Runnable {
public void run(){
fSplashScreen.dispose(); // 关闭封面
}
}
// 变量声明 - 不进行修改//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 jPasswordField1;
private javax.swing.JTextField jTextField1;
// 变量声明结束//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -