📄 achatframe.java
字号:
if(Obj==C.A.B.Password)
C.A.B.Password.setIcon(new ImageIcon("Password1.jpg"));
if(Obj==C.B.B.M.Help)
C.B.B.M.Help.setIcon(new ImageIcon("BHelp1.jpg"));
if(Obj==C.B.B.M.LookFor)
C.B.B.M.LookFor.setIcon(new ImageIcon("BLookFor1.jpg"));
if(Obj==C.B.B.M.Reset)
C.B.B.M.Reset.setIcon(new ImageIcon("BReset1.jpg"));
if(Obj==C.B.B.M.Stop)
C.B.B.M.Stop.setIcon(new ImageIcon("BStop1.jpg"));
if(Obj==C.B.B.M.Recieve)
C.B.B.M.Recieve.setIcon(new ImageIcon("BRecieve1.jpg"));
if(Obj==C.B.B.M.Leave)
C.B.B.M.Leave.setIcon(new ImageIcon("BLeave1.jpg"));
if(Obj==C.B.B.M.Return)
C.B.B.M.Return.setIcon(new ImageIcon("BReturn1.jpg"));
if(Obj==C.B.B.M.Exit)
C.B.B.M.Exit.setIcon(new ImageIcon("BExit1.jpg"));
if(Obj==C.B.B.S.Send)
{
if(i==1)
C.B.B.S.Send.setIcon(new ImageIcon("BSend1.jpg"));
if(i==2)
C.B.B.S.Send.setIcon(new ImageIcon("BSend1.jpg"));
if(i==3)
C.B.B.S.Send.setIcon(new ImageIcon("BSend4.jpg"));
if(i==4)
C.B.B.S.Send.setIcon(new ImageIcon("BSend4.jpg"));
}
if(Obj==C.B.B.F.press)
C.B.B.F.press.setIcon(new ImageIcon("BQ1.jpg"));
}
public void mouseClicked(MouseEvent e)
{
Object Obj=e.getSource();
if(Obj==C.B.M.L.All)//如果按到了所有人按钮
{
C.B.B.S.T2.setText("所有人");
}
if(Obj==C.B.B.M.Help)//如果按到了帮助主题按钮
{
DHelpDialog D=new DHelpDialog(this,"Help",true);
}
if(Obj==C.B.B.S.Press)//如果按到了表情按钮
{
C.B.B.S.Press.setIcon(new ImageIcon("BPress.jpg"));//把选中图片的清空
x=0;
}
if(Obj==C.B.B.M.Exit)//如果按到了退出按钮
{
DExit1Dialog D=new DExit1Dialog(this,"Exit",true);//会有是否退出的确认对话框弹出
}
if(Obj==C.B.B.M.Reset)//如果按到了刷新屏幕按钮
{
C.B.M.T.TA.removeAll();
C.B.M.T.TB.removeAll();
}
if(Obj==C.B.B.M.LookFor)//如果按到了寻找好友按钮
{
if(fcu.CI.getCommand().equals("StopServer") || fcu.CI.getCommand().equals("CloseServer"))
{
DWrong9Dialog D=new DWrong9Dialog(this,"Error",true);//服务器处于关闭状态时弹出对话框
return;
}
DSearch1Frame D=new DSearch1Frame("寻找好友");//弹出寻找好友对话框
}
if(Obj==C.B.B.M.Stop)//如果按到了屏蔽用户按钮
{
if(fcu.CI.getCommand().equals("StopServer") || fcu.CI.getCommand().equals("CloseServer"))
{
DWrong9Dialog D=new DWrong9Dialog(this,"Error",true);//服务器处于关闭状态时弹出对话框
return;
}
DStopDialog D=new DStopDialog(this,"屏蔽",true);//弹出屏蔽用户选择列表
}
if(Obj==C.B.B.M.Recieve)//如果按到了取消屏蔽按钮
{
if(fcu.CI.getCommand().equals("StopServer") || fcu.CI.getCommand().equals("CloseServer"))
{
DWrong9Dialog D=new DWrong9Dialog(this,"Error",true);//服务器处于关闭状态时弹出对话框
return;
}
if(C.B.B.F.T1.getText().length()!=0)
{
C.B.B.F.T1.setText("");
fcu.recieve();//取消屏蔽时调用FChatUser类的recieve()方法
}
else
{
return;
}
}
if(Obj==C.B.B.M.Leave)//如果按到了暂时离开按钮
{
if(fcu.CI.getCommand().equals("StopServer") || fcu.CI.getCommand().equals("CloseServer"))
{
DWrong9Dialog D=new DWrong9Dialog(this,"Error",true);//服务器处于关闭状态时弹出对话框
return;
}
if(C.B.T.State.getText().equals("在线"))//如果用户在线
{
fcu.leave();//调用FChatUser类的leave()方法
C.B.T.State.setForeground(new Color(242,101,34));
C.B.T.State.setText("离开");//设置为离开状态
C.B.T.Face.setIcon(new ImageIcon(CCardFrame.hashmapimage.get(C.A.D.L.TF2.getText())+"a.jpg"));
}
else
return;
}
if(Obj==C.B.B.M.Return)//如果按到了我要回来按钮
{
if(fcu.CI.getCommand().equals("StopServer") || fcu.CI.getCommand().equals("CloseServer"))
{
DWrong9Dialog D=new DWrong9Dialog(this,"Error",true);//服务器处于关闭状态时弹出对话框
return;
}
if(C.B.T.State.getText().equals("离开"))
{
fcu.Return();//调用FChatUser类的Return()方法
C.B.T.State.setForeground(new Color(0,0,0));
C.B.T.State.setText("在线");//把状态改回在线
C.B.T.Face.setIcon(new ImageIcon(CCardFrame.hashmapimage.get(C.A.D.L.TF2.getText())+".jpg"));
}
else
return;
}
}
public void actionPerformed(ActionEvent e)
{
int Select3=C.B.B.F.JB.getSelectedIndex();//得到选择背景组合框的下标
String S=C.A.D.L.TF1.getText().trim();//得到登录框中填写的服务器地址
String U=C.A.D.L.TF2.getText().trim();//得到登录框中填写的用户名
String P=new String(C.A.D.L.TF3.getPassword());//得到登录框中填写的密码
Object Obj=e.getSource();
if(Obj==C.A.B.Login)
{
if(S.length()==0)//验证是否填写了服务器地址
{
DEmpty1Dialog D=new DEmpty1Dialog(this,"Error",true);
return;
}
if(U.length()==0)//验证是否填写了用户名
{
DEmpty2Dialog D=new DEmpty2Dialog(this,"Error",true);
return;
}
if(P.length()==0)//验证是否填写了密码
{
DEmpty3Dialog D=new DEmpty3Dialog(this,"Error",true);
return;
}
else
{
if(U.length()>14)//验证用户名长度是否超过了14
{
DWrong1Dialog D=new DWrong1Dialog(this,"Error",true);
return;
}
if(P.length()>12 || P.length()<6)//验证密码长度是否在6-12之间
{
DWrong2Dialog D=new DWrong2Dialog(this,"Error",true);
return;
}
if(CCardFrame.vuser.contains(U)==false)//验证用户名是否已经被注册过了
{
DWrong14Dialog D=new DWrong14Dialog(this,"Error",true);
return;
}
if(P.equals(CCardFrame.hashmap.get(U))==false)//验证用户名是否与密码相符
{
DWrong15Dialog D=new DWrong15Dialog(this,"Error",true);
return;
}
else
{
fcu.login(this);//调用FChatUser类的login()方法
if(fcu.CI.getCommand().equals("ServerOff"))//如果接收到的命令是服务器关闭着
{
return;
}
if(fcu.CI.getCommand().equals("Cannot in"))//如果接收到的命令是用户被服务器屏蔽中
{
return;
}
if(fcu.CI.getCommand().equals("tryagain"))//如果接收到的命令是昵称已经存在
{
return;
}
else
{
C.m2.setEnabled(true);//菜单栏中"操作"项在用户进入聊天室以后可以使用
C.B.T.Name.setText(fcu.CI.getUser()+" ");//用户的昵称在聊天室左上被显示
//设置用户的头像
C.B.T.Face.setIcon(new ImageIcon(CCardFrame.hashmapimage.get(U)+".jpg"));
System.out.println("Start Chat!!");
/*read to "Customer.txt"
String entry=S+":"+U+":"+P+" ";
try
{
RandomAccessFile log=new RandomAccessFile ("Customer.txt","rw");
log.seek(log.length());
log.writeBytes(entry);
}
catch(IOException ex)
{
JOptionPane.showMessageDialog(M,"can not write to file"+ex);
}*/
C.CL.next(C);
setSize(590,600);
setResizable(false);
show();
//弹出聊天室时总是显示在最中间
Toolkit TK = Toolkit.getDefaultToolkit();
Dimension Size = TK.getScreenSize();
this.setBounds((Size.width-this.getSize().width)/2,
(Size.height-this.getSize().height)/2,
this.getSize().width,this.getSize().height);
}
}
}
}
if(Obj==C.A.B.Reset)//如果按到的是刷新按钮(刷新登录框的TextField)
{
C.A.D.L.TF1.setText("");
C.A.D.L.TF2.setText("");
C.A.D.L.TF3.setText("");
}
if(Obj==C.A.B.Regist)//如果按到的是注册按钮
{
CCardFrame CF=new CCardFrame("");//进入注册界面
dispose();
}
if(Obj==C.A.B.Exit)//如果按到的是退出按钮
{
DExit2Dialog D=new DExit2Dialog(this,"Exit",true);//退出确认
}
if(Obj==C.A.B.Password)//如果按到的是忘记密码按钮
{
CDisPWFrame D=new CDisPWFrame("取回密码");//进入取回密码流程
}
if(Obj==C.B.B.F.JB)//如果按到的是改变背景图片按钮(所有的图片,Panel的背景色,在更改背景时都会改变)
{
if(Select3==0)//一共4种背景可以选择
{
i=1;
//菜单栏部分(下同)
C.mb.setBackground(new Color(27,111,160));
C.m1.setBackground(new Color(27,111,160));
C.m1.setForeground(new Color(229,229,229));
C.m2.setBackground(new Color(27,111,160));
C.m2.setForeground(new Color(229,229,229));
C.m3.setBackground(new Color(27,111,160));
C.m3.setForeground(new Color(229,229,229));
C.mi1.setBackground(new Color(27,111,160));
C.mi1.setForeground(new Color(229,229,229));
C.mi2.setBackground(new Color(27,111,160));
C.mi2.setForeground(new Color(229,229,229));
C.mi3.setBackground(new Color(27,111,160));
C.mi3.setForeground(new Color(229,229,229));
C.mi4.setBackground(new Color(27,111,160));
C.mi4.setForeground(new Color(229,229,229));
C.mi5.setBackground(new Color(27,111,160));
C.mi5.setForeground(new Color(229,229,229));
C.mi6.setBackground(new Color(27,111,160));
C.mi6.setForeground(new Color(229,229,229));
C.mi7.setBackground(new Color(27,111,160));
C.mi7.setForeground(new Color(229,229,229));
C.mi8.setBackground(new Color(27,111,160));
C.mi8.setForeground(new Color(229,229,229));
C.mi9.setBackground(new Color(27,111,160));
C.mi9.setForeground(new Color(229,229,229));
C.mi10.setBackground(new Color(27,111,160));
C.mi10.setForeground(new Color(229,229,229));
C.mi11.setBackground(new Color(27,111,160));
C.mi11.setForeground(new Color(229,229,229));
C.mi12.setBackground(new Color(27,111,160));
C.mi12.setForeground(new Color(229,229,229));
//聊天室改变颜色部分(下同)
C.B.setBackground(new Color(51,157,221));
C.B.T.setBackground(new Color(51,157,221));
C.B.T.T.setBackground(new Color(51,157,221));
C.B.M.setBackground(new Color(51,157,221));
C.B.B.setBackground(new Color(141,211,245));
C.B.B.M.setBackground(new Color(141,211,245));
C.B.B.S.setBackground(new Color(141,211,245));
C.B.B.S.Send.setBackground(new Color(141,211,245));
C.B.B.S.Check.setBackground(new Color(141,211,245));
C.B.B.F.setBackground(new Color(141,211,245));
C.B.B.F.color.setBackground(new Color(141,211,245));
C.B.B.F.font.setBackground(new Color(141,211,245));
C.B.B.F.press.setBackground(new Color(141,211,245));
C.B.M.L.setBackground(new Color(141,211,245));
C.B.M.T.TA.setBackground(new Color(225,247,255));
C.B.M.T.TB.setBackground(new Color(225,247,255));
C.B.M.L.U.setBackground(new Color(206,242,255));
C.B.M.L.U.UserList.setBackground(new Color(206,242,255));
C.B.M.L.U.UserList.setSelectionBackground(new Color(51,157,221));
//聊天室改变图片部分(下同)
C.B.B.F.FontLabel.setIcon(new ImageIcon("BF1.jpg"));
C.B.B.F.Color.setIcon(new ImageIcon("BF2.jpg"));
C.B.B.F.Press.setIcon(new ImageIcon("BF3.jpg"));
C.B.B.F.Background.setIcon(new ImageIcon("BF4.jpg"));
C.B.B.S.Send.setIcon(new ImageIcon("BSend1.jpg"));
C.B.B.S.P.setIcon(new ImageIcon("BR1.jpg"));
C.B.M.T.I1.setIcon(new ImageIcon("BZ1.jpg"));
C.B.M.T.I2.setIcon(new ImageIcon("BZ5.jpg"));
C.B.M.L.Title.setIcon(new ImageIcon("BX1.jpg"));
C.B.M.L.U.I1.setIcon(new ImageIcon("BY1.jpg"));
C.B.M.L.U.I2.setIcon(new ImageIcon("BY5.jpg"));
C.B.B.F.Stop.setIcon(new ImageIcon("BV1.jpg"));
}
if(Select3==1)
{
i=2;
C.mb.setBackground(new Color(62,121,99));
C.m1.setBackground(new Color(62,121,99));
C.m1.setForeground(new Color(229,229,229));
C.m2.setBackground(new Color(62,121,99));
C.m2.setForeground(new Color(229,229,229));
C.m3.setBackground(new Color(62,121,99));
C.m3.setForeground(new Color(229,229,229));
C.mi1.setBackground(new Color(62,121,99));
C.mi1.setForeground(new Color(229,229,229));
C.mi2.setBackground(new Color(62,121,99));
C.mi2.setForeground(new Color(229,229,229));
C.mi3.setBackground(new Color(62,121,99));
C.mi3.setForeground(new Color(229,229,229));
C.mi4.setBackground(new Color(62,121,99));
C.mi4.setForeground(new Color(229,229,229));
C.mi5.setBackground(new Color(62,121,99));
C.mi5.setForeground(new Color(229,229,229));
C.mi6.setBackground(new Color(62,121,99));
C.mi6.setForeground(new Color(229,229,229));
C.mi7.setBackground(new Color(62,121,99));
C.mi7.setForeground(new Color(229,229,229));
C.mi8.setBackground(new Color(62,121,99));
C.mi8.setForeground(new Color(229,229,229));
C.mi9.setBackground(new Color(62,121,99));
C.mi9.setForeground(new Color(229,229,229));
C.mi10.setBackground(new Color(62,121,99));
C.mi10.setForeground(new Color(229,229,229));
C.mi11.setBackground(new Color(62,121,99));
C.mi11.setForeground(new Color(229,229,229));
C.mi12.setBackground(new Color(62,121,99));
C.mi12.setForeground(new Color(229,229,229));
C.B.setBackground(new Color(90,170,140));
C.B.T.setBackground(new Color(90,170,140));
C.B.T.T.setBackground(new Color(90,170,140));
C.B.M.setBackground(new Color(90,170,140));
C.B.B.setBackground(new Color(157,217,183));
C.B.B.M.setBackground(new Color(157,217,183));
C.B.B.S.setBackground(new Color(157,217,183));
C.B.B.S.Send.setBackground(new Color(157,217,183));
C.B.B.S.Check.setBackground(new Color(157,217,183));
C.B.B.F.setBackground(new Color(157,217,183));
C.B.B.F.color.setBackground(new Color(157,217,183));
C.B.B.F.font.setBackground(new Color(157,217,183));
C.B.B.F.press.setBackground(new Color(157,217,183));
C.B.M.L.setBackground(new Color(157,217,183));
C.B.M.T.TA.setBackground(new Color(219,247,241));
C.B.M.T.TB.setBackground(new Color(219,247,241));
C.B.M.L.U.setBackground(new Color(200,240,224));
C.B.M.L.U.UserList.setBackground(new Color(200,240,224));
C.B.M.L.U.UserList.setSelectionBackground(new Color(90,170,140));
C.B.B.F.FontLabel.setIcon(new ImageIcon("BF5.jpg"));
C.B.B.F.Color.setIcon(new ImageIcon("BF6.jpg"));
C.B.B.F.Press.setIcon(new ImageIcon("BF7.jpg"));
C.B.B.F.Background.setIcon(new ImageIcon("BF8.jpg"));
C.B.B.S.Send.setIcon(new ImageIcon("BSend1.jpg"));
C.B.B.S.P.setIcon(new ImageIcon("BR2.jpg"));
C.B.M.T.I1.setIcon(new ImageIcon("BZ2.jpg"));
C.B.M.T.I2.setIcon(new ImageIcon("BZ6.jpg"));
C.B.M.L.Title.setIcon(new ImageIcon("BX2.jpg"));
C.B.M.L.U.I1.setIcon(new ImageIcon("BY2.jpg"));
C.B.M.L.U.I2.setIcon(new ImageIcon("BY6.jpg"));
C.B.B.F.Stop.setIcon(new ImageIcon("BV2.jpg"));
}
if(Select3==2)
{
i=3;
C.mb.setBackground(new Color(164,130,37));
C.m1.setBackground(new Color(164,130,37));
C.m1.setForeground(new Color(229,229,229));
C.m2.setBackground(new Color(164,130,37));
C.m2.setForeground(new Color(229,229,229));
C.m3.setBackground(new Color(164,130,37));
C.m3.setForeground(new Color(229,229,229));
C.mi1.setBackground(new Color(164,130,37));
C.mi1.setForeground(new Color(229,229,229));
C.mi2.setBackground(new Color(164,130,37));
C.mi2.setForeground(new Color(229,229,229));
C.mi3.setBackground(new Color(164,130,37));
C.mi3.setForeground(new Color(229,229,229));
C.mi4.setBackground(new Color(164,130,37));
C.mi4.setForeground(new Color(229,229,229));
C.mi5.setBackground(new Color(164,130,37));
C.mi5.setForeground(new Color(229,229,229));
C.mi6.setBackground(new Color(164,130,37));
C.mi6.setForeground(new Color(229,229,229));
C.mi7.setBackground(new Color(164,130,37));
C.mi7.setForeground(new Color(229,229,229));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -