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

📄 loginframe.java

📁 一个很详细的航空售票系统开发的例子
💻 JAVA
字号:
package com.tarena.abs.client;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.tarena.abs.model.*;


/**
 * 该类描述一个登录窗口
 * @author tony.tang
 *
 */
public class LoginFrame extends JFrame  implements ActionListener{
	/**
	 * 
	 */
	private static final long serialVersionUID = 2400305667603538483L;
	private JLabel[] label;//所有标签
	private JTextField name;
	private JPasswordField password;
	private JButton ok;
	private JButton cancel;
	private JPanel jp1,jp2,jp3;
	public LoginFrame(){
		super("航班机票预定系统--客户登录");
		label=new JLabel[3];
		label[0]=new JLabel("用  户  名:");
		label[1]=new JLabel("密        码:");
		label[2]=new JLabel("客户登录");
		name=new JTextField(20);
		password=new JPasswordField(20);
		ok=new JButton("登录");
		cancel=new JButton("取消");
		jp1=new JPanel();
		jp2=new JPanel();
		jp3=new JPanel();
		init();
		setAllFont();
		addEventHandle();	
	}
	private void init(){
		jp1.setLayout(new FlowLayout(FlowLayout.CENTER,10,20));
		jp1.add(label[2]);
		this.add(jp1,BorderLayout.NORTH);
		jp2.setLayout(new FlowLayout(FlowLayout.CENTER,5,10));
		jp2.add(label[0]);jp2.add(name);
		jp2.add(label[1]);jp2.add(password);
		this.add(jp2,BorderLayout.CENTER);
		jp3.setLayout(new FlowLayout(FlowLayout.CENTER,50,20));
		jp3.add(ok);jp3.add(cancel);
		this.add(jp3,BorderLayout.SOUTH);
	}
	private void setAllFont(){
		Font f1=new Font("",Font.BOLD,20);
		Font f2=new Font("仿宋",Font.BOLD,30);
		for(int i=0;i<label.length-1;i++){
			label[i].setFont(f1);
		}
		label[label.length-1].setFont(f2);
		label[label.length-1].setForeground(Color.RED);
		name.setFont(f1);
		password.setFont(f1);
		ok.setFont(f1);
		cancel.setFont(f1);
	}
	public void showMe(){
		this.setSize(540,360);
		this.setVisible(true);
		//this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	private void addEventHandle(){
		ok.addActionListener(this);
		cancel.addActionListener(this);
	}
	
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("登录")){
			if(name.getText().equals("") || new String(password.getPassword()).equals("")){
				JOptionPane.showMessageDialog(this,"姓名和密码不能为空!");
				return;
			}
			try {
				Request req=new Request("login");
				req.setData("UserName",name.getText());
				req.setData("Password",new String(password.getPassword()));
				ClientMainClass.oos.writeObject(req);
				ClientMainClass.oos.flush();
				Response res=(Response)ClientMainClass.ois.readObject();
				Agent user=(Agent)res.getData();
				if(user!=null){
					ClientMainClass.currentUser=user;
					ClientMainClass.clientFrame=new ClientMainFrame();
					ClientMainClass.clientFrame.showMe();
					this.dispose();
				}else{
					JOptionPane.showMessageDialog(this,"对不起,用户名和密码不正确,请重新输入!");
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			
		}else if(e.getActionCommand().equals("取消")){
			try {
				Request req=new Request("quit");
				ClientMainClass.oos.writeObject(req);
				ClientMainClass.oos.flush();
				System.exit(0);		
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}	
	}
}

⌨️ 快捷键说明

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