📄 logintest.java
字号:
package Barber;
import java.awt.Dimension;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import Barber.Mainpage;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.awt.Toolkit;
public class Logintest extends JFrame {
private static final long serialVersionUID = 1L;
private String s;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JButton jButton = null;
private JLabel jLabel1 = null;
private Mainpage mainpage;
private JPasswordField jPasswordField = null;
private JButton jButton1 = null;
private JLabel jLabel2 = null;
/**
* This is the default constructor
*/
public Logintest() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
try{
BufferedReader in;
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
this.setBounds(new Rectangle((screenWidth - 636)/ 2,(screenHeight - 537)/ 2, 636, 537));
in=new BufferedReader(new FileReader("password.ini"));
s=in.readLine();
}
catch(IOException e)
{
JOptionPane.showMessageDialog(null,"密码读取错误!");
}
this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Barber/top.jpg")));
//this.setBounds(new Rectangle(0, 0, 636, 535));
this.setContentPane(getJContentPane());
this.setTitle("HIT理发店管理系统");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(-1, -1, 133, 509));
jLabel2.setIcon(new ImageIcon(getClass().getResource("/Barber/0007.jpg")));
jLabel2.setText("");
jLabel1 = new JLabel();
jLabel1.setText("请输入密码");
jLabel1.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
jLabel1.setForeground(new Color(153, 0, 51));
jLabel1.setBounds(new Rectangle(265, 411, 71, 22));
jLabel = new JLabel();
jLabel.setText("");
jLabel.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
jLabel.setIcon(new ImageIcon(getClass().getResource("/Barber/0001.jpg")));
jLabel.setBackground(new Color(231, 255, 255));
jLabel.setBounds(new Rectangle(130, -2, 499, 377));
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setBackground(new Color(204, 204, 204));
jContentPane.add(jLabel, null);
jContentPane.add(getJButton(), null);
jContentPane.add(jLabel1, null);
jContentPane.add(getJPasswordField(), null);
jContentPane.add(getJButton1(), null);
jContentPane.add(jLabel2, null);
}
return jContentPane;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(240, 457, 86, 29));
jButton.setIcon(new ImageIcon(getClass().getResource("/Barber/loginb.jpg")));
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String text = jPasswordField.getText();
String ss=text;
if(s.equals(ss))
{
setVisible(false);
if(mainpage==null)
{
mainpage=new Mainpage();
mainpage.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainpage.setVisible(true);
}
}
else
{
JOptionPane.showMessageDialog(null,"密码错误!");
return;
}
}
});
}
return jButton;
}
/**
* This method initializes jPasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setBounds(new Rectangle(371, 410, 88, 23));
jPasswordField.setBackground(new Color(204, 204, 176));
}
return jPasswordField;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(411, 457, 86, 29));
jButton1.setIcon(new ImageIcon(getClass().getResource("/Barber/loginb2.jpg")));
jButton1.setText("");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.exit(0);
}
});
}
return jButton1;
}
} // @jve:decl-index=0:visual-constraint="356,79"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -