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

📄 loginwindow.java

📁 自己做的影碟碟出租管理系统
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class   LoginWindow extends JDialog {  
int LevelChoice=1;
JPanel p1=new JPanel(); //定义并建立面板
JPanel p2=new JPanel();
JPanel p31=new JPanel();
JPanel p4=new JPanel();
JPanel p5=new JPanel();
JPanel p6=new JPanel();
JTextField txtUserName=new JTextField(12); //用户名文本框
JPasswordField txtPwd1=new JPasswordField(12);//密码框

JRadioButton adminButton,userButton;
ButtonGroup group;
JButton ok=new JButton("确定");
JButton cancel=new JButton("取消");
boolean pass=false;
public LoginWindow(){
	
    setModal(true); //设置模态
    setBackground(Color.LIGHT_GRAY);//设置背景色
    Container contentPane=this.getContentPane();//取出内容面板
    contentPane.setLayout(new GridLayout(6,1)); //设置布局为6行1列
    p2.add(new JLabel("用户名"));p2.add(txtUserName); //将组件添加到中间容器
    p31.add(new JLabel(" 密  码"));p31.add(txtPwd1);
    p4.add(ok);p4.add(cancel);
    
    adminButton=new JRadioButton("管理员",true);
    userButton=new JRadioButton("用户",false);
    p5.add(adminButton);p5.add(userButton);
  	
  	group=new ButtonGroup();
    group.add(adminButton);
    group.add(userButton);
    adminButton.addItemListener(new RadioButtonHandler());
    userButton.addItemListener(new RadioButtonHandler());
    ButtonHandler handler=new ButtonHandler();
    ok.addActionListener(handler);
    cancel.addActionListener(handler);
    contentPane.add(p1);   //将面板添加到内容面板
    contentPane.add(p2);
    contentPane.add(p31);
    
    contentPane.add(p5);
    contentPane.add(p4);
    contentPane.add(p6);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);//设置自动关闭窗口
    setSize(300,220);
    Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
    setLocation((screen.width-310)/2,(screen.height-220)/2);
    setTitle("登录窗口");
    setResizable(false); //不让用户改变窗口大小
    setVisible(true);
    }
 
public String GetUserID(){
	return txtUserName.getText();
	}
public String GetUserPassword(){
	return txtPwd1.getText();
	}
public int GetLevelChoice(){
	return LevelChoice;
	}
public void SetLevelChoice(int LevelChoice){
	this.LevelChoice=LevelChoice;
	}
protected void SetPass(){
	pass=true;
	}	
public  boolean IsPass(){
	return pass;
	}
protected void success(){
	JOptionPane.showMessageDialog(null,"成功登陆!");
	}
protected void failure(){
	JOptionPane.showMessageDialog(null,"登陆失败!");
	}
protected void notexist(){
    JOptionPane.showMessageDialog(null,"用户不存在!");	
	}	
	

  private class RadioButtonHandler implements ItemListener{
  	
  	public void itemStateChanged(ItemEvent event){
  		if(event.getItem()==userButton)
  		  SetLevelChoice(2);
  		 else SetLevelChoice(1);
  		}
  	} 
   
   
   private class ButtonHandler implements ActionListener{
   
    public void actionPerformed(ActionEvent e){
    if(e.getSource()==ok){   
       
       if(txtUserName.getText().length()==0 )
    
        { 
         JOptionPane.showMessageDialog(null,"用户名不正确!");
         txtUserName.requestFocus(); 
         txtUserName.setSelectionStart(0);
         txtPwd1.setText("");
        
        }
       else if(txtPwd1.getText().length()==0)
      	 { 
      	 	JOptionPane.showMessageDialog(null,"密码不正确!");
             txtPwd1.requestFocus(); 
             
         }
       else setVisible(false);
    }
      else if(e.getSource()==cancel) //单击取消
      { 
        LoginBack.LoginPass=false;
        dispose();
      }
    }
   }




			
}

⌨️ 快捷键说明

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