📄 loginview.java
字号:
package atm;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.sql.SQLException;
import javax.swing.*;
import javax.swing.event.*;
public class Loginview extends WindowAdapter implements ActionListener,TextListener
{
private Iatm atm;
private JFrame jf;
private JLabel jl1;
private JLabel jl2;
private JLabel jl3;
private JLabel jl4;
private JTextField jt1;
private JTextField jt2;
private JButton jb;
private JPanel jp;
private JPanel jp1;
private JLabel jl5;
public Loginview()
{
jf = new JFrame("用户登录界面");
atm = new Dbatm();
jf.setSize(320,200);
jf.setLocation(100,100);
jp = new JPanel();
jp.setLayout(new FlowLayout(FlowLayout.RIGHT));
jp1 = new JPanel();
jp1.setLayout(new FlowLayout(FlowLayout.RIGHT));
jl1 = new JLabel("帐号:");
jl2 = new JLabel("密码:");
jl3 = new JLabel("帐号可为字符串");
jl4 = new JLabel("密码只能为数字");
jl5 = new JLabel("ATM系统");
jt1 = new JTextField(12);
// jt1.setSize(100,100);
jt2 = new JTextField(12);
jb = new JButton("登陆");
jf.setLayout(new FlowLayout(FlowLayout.CENTER));
jf.add(jl5);
jp.add(jl1);
jp.add(jt1);
jp.add(jl3);
jp1.add(jl2);
jp1.add(jt2);
jp1.add(jl4);
jf.add(jp);
jf.add(jp1);
jf.add(jb);
jf.setVisible(true);
jb.addActionListener(this);
jt1.addActionListener(this);
jt2.addActionListener(this);
//jt1.addTextListener(this);
}
public void actionPerformed(ActionEvent e)
{
try {
if(atm.login(jt1.getText(), Integer.parseInt(jt2.getText())) !=null)
{
new Operate(new User(jt1.getText(), Integer.parseInt(jt2.getText())));
}
else
{
jl3.setText("用户名或密码错误");
}
} catch (NumberFormatException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
public void textValueChanged(TextEvent e)
{
Object source = e.getSource();
String str;
char[] ch = new char[50];
if(source == jt2)
{
str = jt2.getText();
ch = str.toCharArray();
for(int i = 0 ; i < str.length(); i++)
{
if(Character.isLetter(ch[i]))
{
jl4.setBackground(Color.RED);
jl4.setForeground(Color.RED);
jl4.setText("不能输入字母");
}
}
}
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public static void main(String[] args)
{
new Loginview();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -