📄 logframe.java
字号:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class logframe extends JFrame implements ActionListener{
private JLabel label_user;
private JTextField textfield_user;
private JButton button_login;
private JComboBox combobox_user;
private JButton button_canel;
private JLabel label_back;
private JPasswordField passwordfield_password;
private JLabel label_password;
databasemanager dbm;
public logframe(){
initset();
initimage();
initframe();
dbm=new databasemanager();
}
public void initset(){
//初始化设置
}
public void initimage(){
//初始化图片资源
}
public void initframe(){
//初始化窗口
this.setTitle("成绩管理系统");
this.setSize(300, 211);
this.setVisible(true);
getContentPane().setLayout(null);
{
label_user = new JLabel();
getContentPane().add(label_user);
label_user.setText("用户:");
label_user.setFont(allset.font_label);
label_user.setBounds(24, 63, 72, 13);
}
{
label_password = new JLabel();
getContentPane().add(label_password);
label_password.setText("密码:");
label_password.setFont(allset.font_label);
label_password.setBounds(24, 100, 77, 14);
}
{
textfield_user = new JTextField();
getContentPane().add(textfield_user);
textfield_user.setToolTipText("学生使用学号作用户名,管理员使用专用帐户");
textfield_user.setFont(allset.font_textfiled);
textfield_user.setBounds(127, 58, 113, 24);
}
{
passwordfield_password = new JPasswordField();
passwordfield_password.setToolTipText("学生使用身份证作密码,管理员使用专用密码");
getContentPane().add(passwordfield_password);
passwordfield_password.setBounds(127, 96, 113, 18);
}
{
button_login = new JButton();
button_login.addActionListener(this);
button_login.setFont(allset.font_label);
getContentPane().add(button_login);
button_login.setText("登录");
button_login.setBounds(36, 136,80, 25);
}
{
button_canel = new JButton();
button_canel.addActionListener(this);
button_canel.setFont(allset.font_label);
getContentPane().add(button_canel);
button_canel.setText("取消");
button_canel.setBounds(150, 136, 90, 25);
}
{
ComboBoxModel combobox_userModel =
new DefaultComboBoxModel(
new String[] { "普通用户","管理员" });
combobox_user = new JComboBox();
combobox_user.setFont(allset.font_label);
getContentPane().add(combobox_user);
combobox_user.setModel(combobox_userModel);
combobox_user.setBounds(167, 12, 73, 25);
}
{
label_back = new JLabel();
getContentPane().add(label_back);
label_back.setIcon(new ImageIcon(getClass().getResource("/image/back.png")));
label_back.setBounds(0,0,300,211);
}
}
public static void main(String[]s){
new logframe();
}
protected void processWindowEvent(WindowEvent e) {
if(e.getID()==WindowEvent.WINDOW_CLOSING){
actionPerformed(new ActionEvent(button_canel,1001,"取消"));
}
}
public void login(){
String sql="if exists(select * from ";
boolean ifadmini=false;
if(combobox_user.getSelectedItem().equals("普通用户")){
sql+="学生信息表 where 学号='"+textfield_user.getText()+"' and 身份证号='"+
passwordfield_password.getText()+"'";
}
else{
sql+="用户表 where 用户名='"+textfield_user.getText()+"' and 密码='"+
passwordfield_password.getText()+"'";
ifadmini=true;
}
sql+=" )select 'yes' as qq else select 'no' as qq";
ResultSet rset=dbm.select(sql);
try {
String ss=null;
while(rset.next()){
ss=rset.getString("qq");
}
if(ss.equals("yes")){
new mainframe(ifadmini);
dispose();
}
else if(ss.equals("no")){
JOptionPane.showMessageDialog(this,"用户名或密码错误!","错误",
JOptionPane.INFORMATION_MESSAGE);
}
} catch (SQLException e) {
e.printStackTrace();
}
//System.out.println(n);
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource().equals(button_login)){
login();
}
if(ae.getSource().equals(button_canel)){
int i=JOptionPane.showConfirmDialog(this,"是否退出登录?","退出",
JOptionPane.YES_NO_OPTION);
if(i==0){
System.exit(0);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -