浅谈Mediator仲裁者模式,Redis高级项目实战

2021年09月15日 阅读数:1
这篇文章主要向大家介绍浅谈Mediator仲裁者模式,Redis高级项目实战,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。
    setEnabled(enable);

    setBackground( enable? Color.WHITE : Color.BLACK );

}

@Override

public void textValueChanged(TextEvent e) {

    mediator.ColleagueChanged();

}

}java


LoginFrame实现类

package designMode.mediator;git

import java.awt.*;面试

import java.awt.event.ActionEvent;markdown

import java.awt.event.ActionListener;ide

public class LoginFrame extends Frame implements ActionListener, Mediator {学习

private static final long serialVersionUID = -509490729876024682L;

private ColleagueButton buttonOK;

private ColleagueButton buttonCancel;

private ColleagueCheckBox chkGuest;

private ColleagueCheckBox chkUser;

private ColleagueTextField tfUser;

private ColleagueTextField tfPass;

public LoginFrame(String title){

    super(title);

    setBackground(Color.lightGray);

    setLayout(new GridLayout(4,2));

    createColleagues();

    add(chkGuest);

    add(chkUser);

    add(new Label("用户名:"));

    add(tfUser);

    add(new Label("密码:"));

    add(tfPass);

    add(buttonOK);

    add(buttonCancel);

    ColleagueChanged();

    pack();

    show();

}

public void createColleagues() {

    CheckboxGroup chk=new CheckboxGroup();

    chkGuest=new ColleagueCheckBox("Guest",chk,true);

    chkUser=new ColleagueCheckBox("User",chk,false);

    buttonOK=new ColleagueButton("OK");

    buttonCancel=new ColleagueButton("Cancel");

    tfUser=new ColleagueTextField("",10);

    tfPass=new ColleagueTextField("",10);

    tfPass.setEchoChar('#');

    chkGuest.setMediator(this);

    chkUser.setMediator(this);

    buttonOK.setMediator(this);

    buttonCancel.setMediator(this);

    tfUser.setMediator(this);

    tfPass.setMediator(this);

    chkGuest.addItemListener(chkGuest);

    chkUser.addItemListener(chkUser);

    buttonOK.addActionListener(this);

    buttonCancel.addActionListener(this);

    tfUser.addTextListener(tfUser);

    tfPass.addTextListener(tfPass);

}

public void ColleagueChanged() {

    if(chkGuest.getState()){

        tfUser.setColleagueEnable(false);

        tfPass.setColleagueEnable(false);

        buttonOK.setColleagueEnable(true);

    }else{

        tfUser.setColleagueEnable(true);

        userPassChanged();

    }

}

private void userPassChanged() {

    if(tfUser.getText().length()>0){

        tfPass.setColleagueEnable(true);

        if(tfPass.getText().length()>0){

            buttonOK.setColleagueEnable(true);

        }else{

            buttonOK.setColleagueEnable(false);

        }

    }else{

        tfPass.setColleagueEnable(false);

        buttonOK.setColleagueEnable(false);

    }

}

public void actionPerformed(ActionEvent e) {

    System.out.println(e.toString());

    System.exit(0);

}

}this


Main方法

package designMode.mediator;.net

public class Main {code

public static void main(String[] args) {

    LoginFrame login = new LoginFrame("仲裁者模式");

}

}orm



运行结果

游客访问,不用输入用户名和密码,所以禁用。

![99f70158843e22bf9b8f3702abf8a6ee3f1.jpg](https://s2.51cto.com/images/20210912/1631459516218203.jpg)

会员访问,只有输入用户名以后才能输入密码,用户名可用,密码暂不能用,登陆按钮OK不可用。

# 最后

金三银四立刻就到了,但愿你们能好好学习一下这些技术点

**[CodeChina开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频】](https://ali1024.coding.net/public/P7/Java/git)**

学习视频:

![](https://s2.51cto.com/images/20210912/1631459517590263.jpg)

大厂面试真题:

![](https://s2.51cto.com/images/20210912/1631459517800264.jpg)