package com.sjsq;
/**
-
此类为登录窗口类
-
由Visual Editor 生成
-
@author 郑伟
-
@author shuijianshiqing
-
@date 2020-12-30
-
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.jvnet.substance.skin.SubstanceCremeLookAndFeel;
public class Login extends JFrame implements WindowListener, ActionListener, KeyListener {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JTextField jTextField = null;
private JPasswordField jPasswordField = null;
private Connection connection; // @jve:decl-index=0:
private Statement stmt;
private String username;
private int flag = 0;
/**
- This is the default constructor
*/
public Login() {
super();
try {
UIManager.setLookAndFeel(new SubstanceCremeLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
initialize();
Dimension screen = getToolkit().getScreenSize(); // 得到屏幕尺寸
// pack(); //窗口适应组件尺寸
setLocation((screen.width - getWidth()) / 2, (screen.height - getHeight()) / 2);// 使窗口出现在屏幕中间
this.setResizable(false);// 不可缩放~~
this.addWindowListener(this);
connection = DBUtil.getlink();
try {
stmt = connection.createStatement();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} // 链接数据库
}
/**
-
This method initializes this
-
@return void
*/
private void initialize() {
// 登录窗口大小
this.setSize(500, 308);
this.setContentPane(getJContentPane());
this.setTitle(“欢迎登录教材管理系统”);
}
// 登录函数
private void denglu() {
if (flag > 2) {
jButton.setEnabled(false);
}
this.jLabel.setText(“登录中请稍候。。”);
username = jTextField.getText();
String pwd = String.valueOf(jPasswordField.getPassword());
String yz = new String(“Select username,pswd,yanzheng from login where username='” + username + “'”);
try {
ResultSet result = stmt.executeQuery(yz);
if (result.next()) { // 用户名存在~
if (pwd.equals(result.getString(2))) {
if (result.getString(3).equals(“1”)) { // 验证权限
this.jLabel.setText(" 登录成功");
this.flag = 1; // 若取得数据的第三项是1的话,则把flag设置为1
this.setVisible(false);
XFlashScreen splash = new XFlashScreen();
splash.start(); // 运行启动界面
} else if (result.getString(3).equals(“4”)) { // 验证权限
this.jLabel.setText(" 登录成功");
this.flag = 4; // 若取得数据的第三项是4的话,则把flag设置为4
this.setVisible(false);
}
} else {
this.jLabel.setText(" 密码错误 -_-!");
flag++;
}
} else {
this.jLabel.setText(" 没有此用户 -_-!");
flag++;
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
/**
-
This method initializes jContentPane
-
@return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(160, 55, 57, 17));
jLabel1.setText(“账号:”);
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(160, 100, 55, 17));
jLabel2.setText(“密码:”);
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(180, 150, 177, 14));
jLabel.setText("不能尝试超过4次哦~(__) ");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setBackground(new Color(255, 255, 225));
jContentPane.add(getJButton(), null);
jContentPane.add(getJButton1(), null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel1, null);
jContentPane.add(jLabel2, null);
jContentPane.add(getJTextField(), null);
jContentPane.add(getJPasswordField(), null);
}
return jContentPane;
}
public void windowActivated(WindowEvent arg0) {
}
public void windowClosed(WindowEvent arg0) {
System.exit(0);
}
public void windowClosing(WindowEvent arg0) {
}
public void windowDeactivated(WindowEvent arg0) {
}
public void windowDeiconified(WindowEvent arg0) {
}
public void windowIconified(WindowEvent arg0) {
}
public void windowOpened(WindowEvent arg0) {
}
/**
-
This method initializes jButton
-
@return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton(new ImageIcon(“./pic/key.gif”));
jButton.setBounds(new Rectangle(120, 180, 83, 25));
// jButton.setFont(new Font(“Dialog”, Font.BOLD, 11));
jButton.setText(“登录”);
jButton.addActionListener(this);
}
return jButton;
}
/**
-
This method initializes jButton1
-
@return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton(new ImageIcon(“./pic/exit.gif”));
jButton1.addActionListener(this);
jButton1.setBounds(new Rectangle(300, 180, 83, 25));
// jButton1.setFont(new Font(“Dialog”, Font.BOLD, 11));
jButton1.setText(“退出”);
}
return jButton1;
}
/**
-
This method initializes jTextField
-
@return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(200, 45, 156, 35));
jTextField.addKeyListener(this);
}
return jTextField;
}
/**
-
This method initializes jPasswordField
-
@return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setBounds(new Rectangle(200, 90, 156, 35));
jPasswordField.addKeyListener(this);
}
return jPasswordField;
}
public void actionPerformed(ActionEvent e) {
if ((JButton) e.getSource() == jButton1) {
this.dispose();
System.exit(0);
} else if ((JButton) e.getSource() == jButton) {
denglu();
}
}
public void keyPressed(KeyEvent arg0) {
}
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER)/** 判断是否回车 */
denglu();
}
public void keyTyped(KeyEvent arg0) {
}
public static void main(String[] args) {
Login aaa = new Login();
aa
必看视频!获取2024年最新Java开发全套学习资料 备注Java
a.setVisible(true);
}
}
package com.sjsq;
import javax.swing.table.AbstractTableModel;
class MyTable extends AbstractTableModel {
Object[][] p = null;
String[] n = null;
MyTable(Object[][] p, String[] n) {
this.p = p;
this.n = n;
}
public int getColumnCount() {
return n.length;
}
public int getRowCount() {
return p.length;
}
public Object getValueAt(int row, int col) {
return p[row][col];
}
public String getColumnName(int col) {
return n[col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col) {
if (col == 0) {
return false;
} else {
return true;
}
}
public void setValueAt(Object value, int row, int col) {
{
p[row][col] = value;
}
}
}
package com.sjsq;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Rectangle;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
public class XMainFrame extends JFrame implements WindowListener {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTabbedPane jTabbedPane = null;
XAddForm xaddform;
/**
- This is the default constructor
*/
public XMainFrame() {
super();
xaddform = new XAddForm();
initialize();
Dimension screen = getToolkit().getScreenSize(); // 得到屏幕尺寸
// pack(); //窗口适应组件尺寸
setLocation((screen.width - 800) / 2, (screen.height - 600) / 2);
}
/**
-
This method initializes this
-
@return void
*/
private void initialize() {
this.setSize(567, 401);
this.setContentPane(getJContentPane());
this.setTitle(“教材管理系统”);
}
/**
-
This method initializes jContentPane
-
@return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.gridwidth = -1;
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.ipadx = -5;
gridBagConstraints.ipady = -7;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.gridheight = -1;
jContentPane = new JPanel();
jContentPane.setLayout(new GridBagLayout());
jContentPane.add(getJTabbedPane(), gridBagConstraints);
}
return jContentPane;
}
/**
-
This method initializes jTabbedPane
-
@return javax.swing.JTabbedPane
*/
private JTabbedPane getJTabbedPane() {
if (jTabbedPane == null) {
jTabbedPane = new JTabbedPane();
xaddform.setBounds(new Rectangle(1, 2, 558, 366));
jTabbedPane.addTab(“表单提交”, null, xaddform, null);
}
return jTabbedPane;
}
public void windowActivated(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowClosed(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowClosing(WindowEvent arg0) {
// TODO 自动生成方法存根
System.exit(0);
}
public void windowDeactivated(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowDeiconified(WindowEvent arg0) {
// TODO 自动生成方法存根
}
读者福利
由于篇幅过长,就不展示所有面试题了,感兴趣的小伙伴
更多笔记分享
hod initializes jTabbedPane
-
@return javax.swing.JTabbedPane
*/
private JTabbedPane getJTabbedPane() {
if (jTabbedPane == null) {
jTabbedPane = new JTabbedPane();
xaddform.setBounds(new Rectangle(1, 2, 558, 366));
jTabbedPane.addTab(“表单提交”, null, xaddform, null);
}
return jTabbedPane;
}
public void windowActivated(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowClosed(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowClosing(WindowEvent arg0) {
// TODO 自动生成方法存根
System.exit(0);
}
public void windowDeactivated(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowDeiconified(WindowEvent arg0) {
// TODO 自动生成方法存根
}
读者福利
由于篇幅过长,就不展示所有面试题了,感兴趣的小伙伴
[外链图片转存中…(img-cgh66wCD-1716439249421)]
[外链图片转存中…(img-kuOwA4DS-1716439249422)]
[外链图片转存中…(img-wJz0TgfX-1716439249422)]
更多笔记分享
[外链图片转存中…(img-W1g8OjU3-1716439249423)]