⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.java

📁 学生信息管理
💻 JAVA
字号:
package zhuang;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Login implements ActionListener{
	TextField name;
	TextField password;
	public Frame f;
	public static void main( String args[])throws Exception {
		Login lg = new Login();
		lg.createUI();
	}
	public void createUI(){
		f = new Frame("登录界面");
		f.add(new Label("请输入您的用户信息:"),"North");
	    Panel p1 = new Panel();
		p1.setLayout(new BorderLayout());		
		Panel p11 = new Panel();
		p11.setLayout(new GridLayout(2,1));
		p11.add(new Label("用户名:"));
		p11.add(new Label("密  码:"));		
		Panel p12 = new Panel();
		p12.setLayout(new GridLayout(2,1));
		name = new TextField(10);
		name.addActionListener(this);
		password = new TextField(10);
		password.setEchoChar('*');
		password.addActionListener(this);
		p12.add(name);
		p12.add(password);		
		p1.add(p11,"West");
		p1.add(p12,"Center");
		Panel p2 = new Panel();		
		Button submit = new Button("登录");
		Button reset = new Button("取消");
		submit.addActionListener(this);
		reset.addActionListener(this);
		p2.add(submit);
		p2.add(reset);
		f.add(p1,"Center");
		f.add(p2,"South");
		f.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				System.exit(0);	
			}	
		});  
		f.setSize(200,130);
		f.setLocation(300,200);
		f.setVisible( true);
	}
	public void actionPerformed(ActionEvent e){
	    String s = e.getActionCommand();
		if(s.equals("取消"))  System.exit(0); 
	    if(s.equals("登录") || (e.getSource()==name) || (e.getSource()==password)) 
			this.submit();	
	}
	public void submit(){
		String n = name.getText();
		String psw = password.getText();
		if(n.equals("123")&&psw.equals("abc")){
			f.setVisible(false);
		    try{new Student(); }catch (Exception ex) { }
		}
		else 
		   JOptionPane.showMessageDialog(null, "帐号或密码错误!", "警告", JOptionPane.ERROR_MESSAGE);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -