• 中介者模式虚拟聊天室


    今天做了中介者模式---虚拟聊天室的实验,用了差不多两个小时的时间,理解了中介者模式的原理,下面是中介者模式的实验要求和实现。

    实验要求:

    虚拟聊天室实例中增加一个新的具体聊天室类和一个新的具体会员类,要求如下:

    1. 新的具体聊天室中发送的图片大小不得超过20M

    2. 新的具体聊天室中发送的文字长度不得超过100个字符。

    3. 新的具体会员类可以发送图片信息和文本信息。

    4. 新的具体会员类在发送文本信息时,可以在信息后加上时间。

    修改客户端测试类,注意原有系统类代码和客户端代码的修改。

    截图:

    代码:

    package 实验19中介者模式;

    import java.util.*;

    public class Group extends Abcharroom{
    private Hashtable ms=new Hashtable();
    public void register(Member m)
    {
    if(!ms.contains(m)){
    ms.put(m.getname(),m);
    m.setroom(this);
    }
    }
    public void sendtext(String a,String b,String c){
    Member m=(Member)ms.get(b);
    String newm=c;
    newm=c.replaceAll("日","*");
    m.receivetext(a,newm);
    }
    public void sendimage(String a,String b,String c){
    Member m=(Member)ms.get(b);
    if(c.length()>5){
    System.out.println("图片较大,发送失败");
    }else{
    m.receiveimage(a,c);
    }
    }
    }

    package 实验19中介者模式;

    import java.util.*;

    public class Group extends Abcharroom{
    private Hashtable ms=new Hashtable();
    public void register(Member m)
    {
    if(!ms.contains(m)){
    ms.put(m.getname(),m);
    m.setroom(this);
    }
    }
    public void sendtext(String a,String b,String c){
    Member m=(Member)ms.get(b);
    String newm=c;
    newm=c.replaceAll("日","*");
    m.receivetext(a,newm);
    }
    public void sendimage(String a,String b,String c){
    Member m=(Member)ms.get(b);
    if(c.length()>5){
    System.out.println("图片较大,发送失败");
    }else{
    m.receiveimage(a,c);
    }
    }
    }

    package 实验19中介者模式;

    public abstract class Abcharroom {
    public abstract void register(Member m);
    public abstract void sendtext(String a,String b,String mess);
    public abstract void sendimage(String a,String b,String mess);
    }

    package 实验19中介者模式;


    public class main {
    public static void main(String args[]){
    Abcharroom r1=new Room();
    Member m1,m2,m3;
    m1=new Xin("A");
    m2=new Xin("B");
    m3=new Xin("C");
    r1.register(m1);
    r1.register(m2);
    r1.register(m3);
    m1.sendtext("B",":玩什么玩,代码敲了吗");
    m2.sendtext("A",":就你能说");
    m2.sendtext("A",":才加上你把---------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
    m1.sendtext("B","呵呵");
    m3.sendimage("A",":坏笑.jpg-----------------------------------------");
    m3.sendimage("B",":坏笑.jpg");

    }
    }

    package 实验19中介者模式;


    public class Pu extends Member{
    public Pu(String a){
    super(a);
    }
    public void sendtext(String a,String c){
    System.out.println("普通会员发送消息");
    room.sendtext(name,a,c);
    }
    public void sendimage(String a,String c){
    System.out.println("普通会员不能发送图片");
    }
    }

    package 实验19中介者模式;

    public class Xin extends Member{
    public Xin(String a){
    super(a);
    }
    public void sendtext(String a,String c){
    System.out.println("新会员发送消息");
    room.sendtext(name,a,c);
    }
    public void sendimage(String a,String c){
    System.out.println("新会员不能发送图片");
    room.sendimage(name,a,c);
    }
    }

  • 相关阅读:
    Mysql:Changes in MySQL 5.6.6 (2012-08-07, Milestone 9):Group-Commit等等:重大变化版本!
    Mysql:Changes in MySQL 5.6.9 (2012-12-11, Release Candidate):GTID-based variables have been 【renamed】
    Mysql:Changes in MySQL 5.6.13 (2013-07-31, General Availability):不再支持可能引起混乱的【选项缩略】写法!
    Mysql:Changes in MySQL 5.6.22 (2014-12-01, General Availability):【sql-log-bin】
    Mysql:Changes in MySQL 5.6.30 (2016-04-11, General Availability):--ssl-mode:
    Mysql:Changes in MySQL 5.6.34 (2016-10-12, General Availability):secure-file-priv
    Windows Linux子系统Windows 10安装指南
    WSL2-参考的对象类型不支持尝试的操作。
    Win10开启Hyper-V后无法运行VMware虚拟机的解决方法
    Kubernetes---高可用的 K8S 集群构建
  • 原文地址:https://www.cnblogs.com/092e/p/15530417.html
Copyright © 2020-2023  润新知