📄 chatroom.java
字号:
chuanwenjian.setBounds(new Rectangle(104, 223, 43, 30));
chuanwenjian.setBorder(null);
jlabel10.setText("收到消息");
jlabel11.setText("注意!如果你建立这个组你就是管理员了."+"\n"
+"输入组的名字.") ;
jlabel10.setBounds(new Rectangle(7, 13, 143, 18));
c=new ImageIcon("4.gif");
chuanwenjian.setIcon(c) ;
chuanwenjian.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
chuanwenjian_mouseClicked(e);
}
});
this.getContentPane().add(tianjia, null);
this.getContentPane().add(fenzu, null);
this.getContentPane().add(fasong, null);
this.getContentPane().add(jScrollPane1, null);
jScrollPane1.getViewport().add(xianshi, null);
this.getContentPane().add(jScrollPane2, null);
jScrollPane2.getViewport().add(shuru, null);
this.getContentPane().add(chuanwenjian, null);
this.getContentPane().add(jScrollPane3, null);
this.getContentPane().add(togroup, null);
this.getContentPane().add(flade, null);
this.getContentPane().add(see, null);
jlabel10.setText("收到消息");
jlabel11.setBounds(new Rectangle(7, 13, 200, 18));
mingcheng.setBounds(new Rectangle(17, 30, 220, 24) );
jlabel10.setBounds(new Rectangle(7, 13, 143, 18));
oneaddme.setBounds(new Rectangle(7, 57, 247, 18));
addit2.setBounds(new Rectangle(19, 124, 93, 29));
addit3.setBounds(new Rectangle(90, 124, 80, 29));
addit.setBounds(new Rectangle(19, 124, 93, 29));
addit2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
addit2_mouseClicked(e);
}});
addit3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
addit3_mouseClicked(e);
}});
addit.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
addit_mouseClicked(e);
}});
iknow2.setBounds(new Rectangle(164, 124, 79, 29));
iknow2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
iknow2_mouseClicked(e);}});
iknow.setBounds(new Rectangle(164, 124, 79, 29));
iknow.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
iknow_mouseClicked(e);}});
jlabel10.setText("加你为组员 !") ;
fenzutishi.getContentPane().add(jlabel11, null);
fenzutishi.getContentPane().add(mingcheng, null);
fenzutishi.getContentPane().add(addit2, null);
fenzutishi.getContentPane().add(iknow2, null);
OneAddyou.getContentPane().add(jlabel10, null);
OneAddyou.getContentPane().add(oneaddme, null);
OneAddyou.getContentPane().add(addit, null);
OneAddyou.getContentPane().add(iknow, null);
OneAddyou.getContentPane().add(addit3, null);}
//-->
void fasong_mouseClicked(MouseEvent e) throws IOException {
String s;
if ( !(s=shuru.getText()).trim() .equals("") ) {
if( xuanze==false ){
try{
byte[] data=s.getBytes();
out.println("liaotian") ;
out.println(myjicq) ;
String a=in.readLine().trim() ;
while(!a.equals("false") ){
System.out.println(a) ;
//String name =in.readLine().trim() ;
sendPacket=new DatagramPacket(data,s.length(),InetAddress.getByName(a),4040);
sendSocket.send(sendPacket);
xianshi.append("你对 "+a+" 说 : "+s+"\n");
a=in.readLine().trim() ;
}
}
catch(IOException e2){
System.out.println(" chatroom li chucuole ") ;
e2.printStackTrace();}
}
else{
try{
byte[] data=s.getBytes();
index=list.getSelectedIndex();
if(index<0)
JOptionPane.showMessageDialog(null,"请先选择对话的对象") ;
else{
theip=friendips.get(index).toString().trim() ;//ip address
String name=friendnames.get(index).toString().trim() ;
if (theip.equals("null")||theip.equals(" ")||theip.equals("0")){
JOptionPane.showMessageDialog(this,"对不起,不在线","ok",JOptionPane.INFORMATION_MESSAGE);
}
else{
sendPacket=new DatagramPacket(data,s.length(),InetAddress.getByName(theip),4040);
sendSocket.send(sendPacket);
xianshi.append("你对 "+name+" 说 : "+s+"\n");
}
}
}
catch(IOException e2){
e2.printStackTrace();}
}
}
shuru.setText("");
}
void tianjia_mouseClicked(MouseEvent e) {
findf.show();
}
void addit_mouseClicked(MouseEvent e) {
out.println("addnewfriend");
out.println(tempgetjicq);
out.println(myjicq);
String thename=" ";
try{
String thejicqno,theip,thestatus,picinfo,email,infos;
do{
thename=in.readLine();
if(thename.equals("over"))
break;
friendnames.add(thename);
thejicqno=in.readLine();
friendjicq.add(new Integer(thejicqno));
theip=in.readLine();
friendips.add(theip);
thestatus=in.readLine();
status.add(thestatus);
picinfo=in.readLine();
picno.add(new Integer(picinfo));
email=in.readLine();
friendemail.add(email);
infos=in.readLine();
friendinfo.add(infos);
}
while(!thename.equals("over"));
}catch(IOException e1){
System.out.println("false");}
int dddd=friendnames.size()-1;
DefaultListModel mm2=(DefaultListModel)list.getModel();
int picid;
picid=Integer.parseInt(picno.get(dddd).toString());
mm2.addElement(new Object[]{friendnames.get(dddd),new ImageIcon(picsonline[picid])});
OneAddyou.dispose();
}
void addit3_mouseClicked(MouseEvent e) {
JOptionPane.showMessageDialog(null,tempgetjicq+"加你为组员!") ;
}
void addit2_mouseClicked(MouseEvent e) {
String name =mingcheng.getText().trim() ;
if(name.length() <1)
{
JOptionPane.showMessageDialog(null,"名字不能为空!") ;
}
else
{
out.println("group") ;
out.println(name);
out.println(myjicq);
String s = null;
try {
s = InetAddress.getLocalHost().toString();
int a=s.indexOf("/");
String s2=s.substring(a+1,s.length() ) ;
out.println(s2) ;
}
catch (UnknownHostException ex) {
out.println("false") ;}
}
fenzutishi.dispose();
}
/////////////////////////////////////////////////////////////////////////////
void iknow_mouseClicked(MouseEvent e) {
OneAddyou.dispose();
}
////////////////////////////////////////////////////////////////////////////
void iknow2_mouseClicked(MouseEvent e) {
fenzutishi.dispose();
}
///////////////////////////////////////////////////////////////////////////
void fenzu_mouseClicked(MouseEvent e) {
fenzutishi.setBounds(400,300,300,200);
fenzutishi.show() ;
}
///////////////////////////////////////////////////////////////////////////
class ChatRoom_fasong_mouseAdapter extends java.awt.event.MouseAdapter {
ChatRoom adaptee;
ChatRoom_fasong_mouseAdapter(ChatRoom adaptee) {
this.adaptee = adaptee;}
public void mouseClicked(MouseEvent e) {
try {adaptee.fasong_mouseClicked(e);}
catch (IOException ex) {}}
void this_windowClosing(WindowEvent e) {
System.exit(0) ;
}
}
class NameAndPicListModel extends DefaultListModel
{
public NameAndPicListModel(Vector friendnames,String [] pics)
{ for(int i=0;i<friendnames.size();++i){
addElement(new Object[]{friendnames.get(i),new ImageIcon(pics[i])});
}
}
public String getName(Object object)
{ Object[] array=(Object[])object;
return(String) array[0];
}
public Icon getIcon(Object object)
{ Object[] array=(Object[]) object;
return (Icon) array[1];
}
}
class NameAndPicListCellRenderer extends JLabel implements ListCellRenderer
{ private Border lineBorder=BorderFactory.createLineBorder(Color.red,2),
emptyBorder =BorderFactory.createEmptyBorder(2,2,2,2);
public NameAndPicListCellRenderer(){
setOpaque(true);
}
public Component getListCellRendererComponent(JList list,Object value,int index,
boolean isSelected,boolean cellHasFocus)
{ NameAndPicListModel model=(NameAndPicListModel) list.getModel();
setText(model.getName(value));
setIcon(model.getIcon(value));
if(isSelected){setForeground(list.getSelectionForeground());
setBackground(list.getSelectionBackground());
}
else { setForeground(list.getForeground());
setBackground(list.getBackground());}
if(cellHasFocus) setBorder(lineBorder);
else setBorder(emptyBorder);
return this;
}
}
class ChatRoom_this_windowAdapter extends java.awt.event.WindowAdapter {
ChatRoom adaptee;
ChatRoom_this_windowAdapter(ChatRoom adaptee) {
this.adaptee = adaptee;
}
}
class ChatRoom_tianjia_mouseAdapter extends java.awt.event.MouseAdapter {
ChatRoom adaptee;
ChatRoom_tianjia_mouseAdapter(ChatRoom adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.tianjia_mouseClicked(e);
}
}
void togroup_mouseClicked(MouseEvent e) {
xuanze=!xuanze;
}
void see_mouseClicked(MouseEvent e) {
findf2.show() ;
}
void chuanwenjian_mouseClicked(MouseEvent e) {
String s = null; int a = 0;int b=0;
try {
s = InetAddress.getLocalHost().toString();
a = s.indexOf("/");
System.out.println(s);}
catch (UnknownHostException ex) {
}
String s2=s.substring(a+1,s.length() ) ;
String s3="wenjian"+s2;
byte[] data=s3.getBytes();
index=list.getSelectedIndex();
System.out.println(index);
if(index<0)
JOptionPane.showMessageDialog(null,"请先选择对象") ;
else{
try {
theip=friendips.get(index).toString().trim() ;
System.out.println(s3);
System.out.println(InetAddress.getByName(theip)) ;
sendPacket = new DatagramPacket(data, s3.length(),InetAddress.getByName(theip), 4040);
sendSocket.send(sendPacket);
System.out.println(s3) ;
}
catch (Exception ex1) {
}
try
{
Send send = new Send(4070);
send.show();
Thread t=new Thread(s);
t.start();
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch(Exception ex)
{}
}}
void flade_mouseClicked(MouseEvent e) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -