JAVA创建一登录窗体,输入用户名和密码登陆



import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class LoginGUI extends JFrame{
	public LoginGUI() {
		setTitle("登录窗口"); 			 					//设置标题
		setLayout(null);     								//设置绝对布局
		Container c = getContentPane(); 					//定义一个容器
		final JTextField jtf1 = new JTextField(); 			//用户名文本框
		final JPasswordField jpf1 = new JPasswordField();	//密码文本框
		JLabel jl1 = new JLabel("用户名:"); 				//“用户名”标签
		JLabel jl2 = new JLabel("密码:");    				//“密码:”标签
		jpf1.setEchoChar('*');								//设置密码字符为*
		JButton jb1 = new JButton("确定");					//“确定”按钮
		JButton jb2 = new JButton("取消");					//“取消”按钮
		jb1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String name = jtf1.getText().trim();
				String psw = new String(jpf1.getPassword());
				if (jtf1.getText().trim().length() == 0 || new String(jpf1.getPassword()).trim().length() == 0) {
					JOptionPane.showMessageDialog(null, "不能为空!");
				}
			

你可能感兴趣的:(JAVA)