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

📄 logindialog.java

📁 参考了JAVA方面MIS系统开发的书籍做的一个 电力收费的系统,包里面是可以直接运行的JAR文件了...SRC是源文件可一些需要的包...数据库是用的MSQLserver2000,"java程序数据
💻 JAVA
字号:
import java.awt.image.ImageProducer;
import java.net.*;
import javax.swing.*;     
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import javax.swing.border.*;
import edu.njust.cs.*;
public class LoginDialog extends JDialog implements ActionListener{
	JLabel labUser=new JLabel("  用  户  ");
	JTextField  txtUser=new JTextField();
	JLabel labPwd=new JLabel("  密  码  ");
	JPasswordField  txtPwd=new JPasswordField();
	JButton btnLogin=new JButton("登  录");
	JButton btnCancel=new JButton("取  消");	
	static int OK=1;
	static int CANCEL=0;	
	int actionCode=0;	
	public LoginDialog(Frame f,String s,boolean b){ 		
		super(f,s,b);	
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);	
		btnLogin.setIcon(new ImageIcon("image/ok20.gif"));	
		btnCancel.setIcon(new ImageIcon("image/cancel20.gif"));	
		btnLogin.addActionListener(this);
		btnCancel.addActionListener(this);
		txtUser.addActionListener(this);
		txtPwd.addActionListener(this);			
		this.labUser.setIcon(new ImageIcon("image/user20.gif"));
		this.labPwd.setIcon(new ImageIcon("image/key20.gif"));
		JPanel panel=new JPanel();
		panel.setLayout(new GridBagLayout());
		Insets insets=new Insets(2,2,2,2);		
		LayoutUtil.add(panel,GridBagConstraints.NONE,
					   GridBagConstraints.CENTER,0,0,0,0,1,1,labUser,insets);
		LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,
					   GridBagConstraints.CENTER,100,0,1,0,1,1,txtUser,insets);
		LayoutUtil.add(panel,GridBagConstraints.NONE,
					   GridBagConstraints.CENTER,0,0,0,1,1,1,labPwd,insets);
		LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,
					   GridBagConstraints.CENTER,100,0,1,1,1,1,txtPwd,insets);
		LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,
					   GridBagConstraints.CENTER,100,0,0,2,1,1,btnLogin,insets);
		LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,
					   GridBagConstraints.CENTER,100,0,1,2,1,1,btnCancel,insets);		
		this.getContentPane().add(panel,"Center");
		this.setSize(200,120);
		Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
		
		this.setLocation((d.width-200)/2,(d.height-120)/2);
		this.setResizable(false);
		this.getRootPane().setDefaultButton(this.btnLogin);
	}
	public void actionPerformed(ActionEvent e){
		Object source=e.getSource();
		if(source==btnLogin){
			actionCode=OK;
			this.setVisible(false);
		}else if(source==btnCancel){
			actionCode=CANCEL;
			this.setVisible(false);
		}else if(source==this.txtUser)
			txtUser.transferFocus();
		else if(source==this.txtPwd)
			txtPwd.transferFocus();
	}
	public int getActionCode(){
		return this.actionCode;
	}
	public String getUser(){
		return this.txtUser.getText().trim();		
	}
	public String getPwd(){
		return new String(this.txtPwd.getPassword());		
	}
}

⌨️ 快捷键说明

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