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

📄 loginframe.java

📁 这是我在北大青鸟accp4.0 第一学期 的java 项目<员工管理系统>,采用db,model,view,三层关系. 连接数据库驱动为jdbc 用eclipse完成的手写的窗体代码,
💻 JAVA
字号:
package com.accp.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.*;
import com.accp.model.LoginModel;
import com.accp.view.mainland;
/**
 * 登陆界面
 * @author Administrator
 *
 */
public class LoginFrame {
	static JFrame frame;
	JTextField txtname;
	JPasswordField txtpass;
	JButton btOk;
	JButton btcan;
	
	public static void main(String[] args) {
		//static JFrame frame=new JFrame();
		JFrame.setDefaultLookAndFeelDecorated(true);
		LoginFrame lg=new LoginFrame();
		lg.execute();
	}
	
	public void execute(){		
		frame=new JFrame(" 登陆 ");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);		
//		 Center the window
	    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	    Dimension frameSize = frame.getSize();
	    if (frameSize.height > screenSize.height) {
	      frameSize.height = screenSize.height;
	    }
	    if (frameSize.width > screenSize.width) {
	      frameSize.width = screenSize.width;
	    }
	    frame.setLocation( screenSize.width  /6 ,
	                      screenSize.height/7 );
	    frame.setVisible(true);
	  
		
		JPanel pane=new JPanel();
	
		pane.setLayout(null);
		pane.setBounds(new Rectangle( -2, 0, 821, 380));
		JLabel lb=new JLabel();
		lb.setText("用户:");
		lb.setBounds(new Rectangle(139, 286, 57, 23));
		JLabel lb2=new JLabel();
		lb2.setText("密码:");
		lb2.setBounds(new Rectangle(306, 284, 67, 27));
		JLabel lb3=new JLabel();
		lb3.setIcon(new ImageIcon("e:\\125\\src\\1.jpg"));
		lb3.setBounds(new Rectangle(2, 0, 779, 213));
		txtname=new JTextField(15);//name文本框
		txtname.setBounds(new Rectangle(203, 286, 93, 24));
		txtpass=new JPasswordField(15);//pass密码框
		txtpass.setBounds(new Rectangle(350, 284, 97, 23));
		btOk=new JButton("登陆");		//登陆按钮
		btOk.setBounds(new Rectangle(201, 318, 93, 26));
		btOk.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
		btOk.setBorder(BorderFactory.createLineBorder(Color.black));
		btOk.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {	
				String name;
				String pass;
				// if(txtname.getText().length()<=0||txtpass.getText().length()<=0)
			     //   {
			      //      JOptionPane.showMessageDialog(null, "没填完整!");
			      //  }
				
				
				try {
					name=txtname.getText();		//得到name值
					pass=txtpass.getText();		//得到pass值
				} catch (Exception ex) {
					JOptionPane.showMessageDialog(null, "请重新输入");
					return;
				}					
				//实例一个模型层对象
				LoginModel lm=new LoginModel();
				
		
				//	JComponent frame;
					frame.setVisible(false);
				//如果条件为真,即登录成功
				if(lm.login(name,pass)){
					JOptionPane.showMessageDialog(null, "登录成功");
					mainland ma=new mainland();
					ma.go(); 
				//	JComponent frame;
				//	frame.setVisible(false);
					frame.dispose();
					//登陆后显示主窗体
				}
				else{
					JOptionPane.showMessageDialog(null, "用户名或密码错误!");
					execute();
				}
			}
			
		});
		btcan=new JButton("取消");
		btcan.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
		btcan.setBounds(new Rectangle(348, 319, 97, 26));
		btcan.setBorder(BorderFactory.createLineBorder(Color.black));
		btcan.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e) {
				 //监听取消按钮事件
		           System.exit(0);
			}
			
		});
		pane.add(lb3);
		pane.add(lb);
		pane.add(txtname);
		pane.add(lb2);
		pane.add(txtpass);
		pane.add(btOk);
		pane.add(btcan);
		frame.getContentPane().add(pane);
	//	frame.pack();
		frame.setSize(788, 425);
		frame.setResizable(false);
		frame.setVisible(true);
	}
}

⌨️ 快捷键说明

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