import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
import java.util.GregorianCalendar;
import javax.swing.JDialog;
import java.io.*;
public class MyselfChat extends Frame implements ActionListener{
Label label1=new Label("请输入你要发送的信息(限英文):");
Label label3=new Label("把以上消息发给右边所填写的IP地址");
TextArea input=new TextArea("",7,14,TextArea.SCROLLBARS_VERTICAL_ONLY);
TextArea output=new TextArea("",18,14,TextArea.SCROLLBARS_VERTICAL_ONLY);
TextField IPAdd=new TextField("10.255.8.86");
Button send=new Button("发送消息");
Button clear=new Button("清空消息");
GregorianCalendar time = new GregorianCalendar();
Container con;
MenuItem readin;
MyselfChat(){
//下面代码用来实现菜单栏!
MenuBar mb = new MenuBar();
Menu file = new Menu("文件");
Menu chat = new Menu("聊天");
Menu disport = new Menu("娱乐");
Menu yingyong = new Menu("应用");
Menu toolkits = new Menu("工具");
Menu help = new Menu("帮助");
Menu readout = new Menu("导出[O]");
MenuShortcut sl1 = new MenuShortcut('I'), //实现快捷键功能
sl2 = new MenuShortcut('O'),
sl3 = new MenuShortcut('B'),
sl4 = new MenuShortcut('C'),
sl5 = new MenuShortcut('K'),
sl6 = new MenuShortcut('E'),
sl7 = new MenuShortcut('U'),
sl8 = new MenuShortcut('D');
myMenuItemListener itemListener = new myMenuItemListener(this);
readin = new MenuItem("导入[I]",sl1);
readin.addActionListener(itemListener);
file.add(readin);
MenuItem backUp = new MenuItem("备份[B].....",sl3);
backUp.addActionListener(itemListener);
readout.add(backUp);
readout.addSeparator();
MenuItem backUpIntxt = new MenuItem("导出聊天记录为文本文件[C]",sl4);
backUpIntxt.addActionListener(itemListener);
readout.add(backUpIntxt);
MenuItem backUpInbackUptxt = new MenuItem("导出聊天记录为备份文件[K]",sl5);
backUpInbackUptxt.addActionListener(itemListener);
readout.add(backUpInbackUptxt);
readout.addActionListener(itemListener);
file.add(readout);
file.addSeparator(); //在菜单项之间加上分割线
MenuItem UpPass = new MenuItem("上传聊天记录[U]",sl7);
UpPass.addActionListener(itemListener);
file.add(UpPass);
MenuItem DownLoad = new MenuItem("下载聊天记录[D]",sl8);
DownLoad.addActionListener(itemListener);
file.add(DownLoad);
file.addSeparator(); //在菜单项之间加上分割线
MenuItem Exit = new MenuItem("退出[E]",sl6);
Exit.addActionListener(itemListener);
file.add(Exit);
MenuItem shipin = new MenuItem("视频聊天");
shipin.addActionListener(itemListener);
chat.add(shipin);
MenuItem yuyin = new MenuItem("语音聊天");
yuyin.addActionListener(itemListener);
chat.add(yuyin);
MenuItem music = new MenuItem("音乐");
music.addActionListener(itemListener);
disport.add(music);
MenuItem film = new MenuItem("电影");
film.addActionListener(itemListener);
disport.add(film);
MenuItem game = new MenuItem("游戏");
game.addActionListener(itemListener);
disport.add(game);
MenuItem sharefiles = new MenuItem("共享文件");
sharefiles.addActionListener(itemListener);
yingyong.add(sharefiles);
MenuItem distancehelp = new MenuItem("远程协助");
distancehelp.addActionListener(itemListener);
yingyong.add(distancehelp);
MenuItem view = new MenuItem("视图");
view.addActionListener(itemListener);
toolkits.add(view);
MenuItem addfriend = new MenuItem("添加好友");
addfriend.addActionListener(itemListener);
toolkits.add(addfriend);
MenuItem about = new MenuItem("关于");
about.addActionListener(itemListener);
help.add(about);
mb.add(file);
mb.add(chat);
mb.add(disport);
mb.add(yingyong);
mb.add(toolkits);
mb.add(help);
this.setMenuBar(mb);
//con = this.getContentPane();
this.setLayout(new BorderLayout());
this.setSize(480,500);
String s = this.IPAdd.getText();
this.setTitle("与"+s+"聊天中");
this.setResizable(false);
this.setBackground(Color.orange);
label1.setFont(new Font("宋体",Font.PLAIN,12));
label1.setForeground(new Color(0,0,192));
label1.setBounds(8,28,216,16);
input.setBackground(new Color(128,255,255));
input.setFont(new Font("",Font.BOLD,15));
input.setForeground(Color.magenta);
input.setBounds(8,44,248,120);
output.setBackground(new Color(128,255,255));
output.setFont(new Font("",Font.PLAIN,12));
output.setForeground(Color.magenta);
output.setBounds(264,44,248,120);
output.setEditable(false);
send.setFont(new Font("新宋题",Font.PLAIN,12));
send.setLocation(136,188);
send.setSize(120,22);
clear.setFont(new Font("新宋体",Font.PLAIN,12));
clear.setLocation(392,188);
clear.setSize(120,22);
label3.setFont(new Font("宋体",Font.PLAIN,12));
label3.setForeground(new Color(0,0,192));
label3.setBounds(8,172,160,16);
IPAdd.setFont(new Font("新宋体",Font.PLAIN,12));
IPAdd.setLocation(8,190);
IPAdd.setSize(120,19);
Panel p1 = new Panel();
p1.setLayout(new GridLayout(2,1));
p1.add(this.label1);
p1.add(this.input);
add(p1,BorderLayout.CENTER);
Panel p2 = new Panel();
p2.setLayout(new GridLayout(1,1));
p2.add(this.output);
add(p2,BorderLayout.NORTH);
Panel p3 = new Panel();
p3.setLayout(new FlowLayout());
p3.add(this.label3);
p3.add(this.IPAdd);
p3.add(this.send);
p3.add(this.clear);
add(p3,BorderLayout.SOUTH);
addWindowListener(new myWindowListener(this));
send.addActionListener(this);
clear.addActionListener(this);
show();
waitForData();
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==send){
sendData();
}
else if(e.getSource()==clear)
output.setText("");
}
public static void main(String[] args){ //主函数
new MyselfChat();
}
void sendData(){
try{
String msg=input.getText();
if(msg.equals(""))
return;
input.setText("");
String ad = IPAdd.getText(); //获取用户输入的IP地址
InetAddress tea = InetAddress.getLocalHost(); //获取本机的IP地址
String asd = tea.getHostAddress();
output.append("["+asd+"]:("+time.get(GregorianCalendar.YEAR)
+"-"+time.get(GregorianCalendar.MONTH)+
"-"+time.get(GregorianCalendar.DATE)+""
+time.get(GregorianCalendar.HOUR)+":"
+time.get(GregorianCalendar.MINUTE)+":"
+time.get(GregorianCalendar.SECOND)+")"+"\n"+msg+"\n");
msg="From ["+asd+"]:("+time.get(GregorianCalendar.YEAR)
+"-"+time.get(GregorianCalendar.MONTH)+
"-"+time.get(GregorianCalendar.DATE)+""
+time.get(GregorianCalendar.HOUR)+":"
+time.get(GregorianCalendar.MINUTE)+":"
+time.get(GregorianCalendar.SECOND)+") \n"+msg ;
InetAddress address=InetAddress.getByName(ad);
int len = msg.length();
byte[] message=new byte[len];
msg.getBytes(0,len,message,0);
DatagramPacket packet=new DatagramPacket(message,len,address,9999);
DatagramSocket socket=new DatagramSocket( );
socket.send(packet);
}catch(Exception e){}
}
void waitForData(){
try{
byte[]
xjch7703
- 粉丝: 11
- 资源: 16
最新资源
- ccceeeeee,ukytkyk/liyihm
- 100kW微型燃气轮机Simulink建模,微燃机包括压缩机模块、容积模块、回热器模块、燃烧室模块、膨胀机模块、转子模块以及控制单元模块 考虑微燃机变工况特性下的流量、压缩绝热效率、膨胀绝热效率、压
- 该模型采用龙贝格观测器进行无传感器控制 其利用 PMSM 数学模型构造观测器模型,根据输出的偏差反馈信号来修正状态变量 当观测的电流实现与实际电流跟随时, 可以从观测的反电势计算得到电机的转子位置信
- 双移线驾驶员模型,多项式双移线模拟 软件使用:Matlab Simulink 适用场景:采用多项式搭建双移线期望路径,基于郭孔辉单点预瞄理论,搭建双移线simulink驾驶员模型 模型包含:双移线
- 0cd39e46e9672ca3fc70d6cb46f099dd_1734832088456_8
- 伺服系统永磁同步电机矢量控制调速系统在线转动惯量辨识Matlab仿真 1.模型简介 模型为永磁同步电机伺服控制仿真,采用Matlab R2018a Simulink搭建 模型内主要包含使
- newEditor.css
- 读QFLASH ID和读4线FLASH数据vitis验证工程
- 欧拉系统(openEuler-22.03-LTS-SP3) suricata rpm安装包
- ADRC自抗扰控制永磁同步电机矢量控制调速系统Matlab仿真模型 1.模型简介 模型为基于自抗扰控制(ADRC)的永磁同步电机矢量控制仿真,采用Matlab R2018a Simulink搭
- ADRC线性自抗扰控制感应电机矢量控制调速Matlab Simulink仿真 1.模型简介 模型为基于线性自抗扰控制(LADRC)的感应(异步)电机矢量控制仿真,采用Matlab R2018a
- 感应电机矢量控制调速仿真PI参数自整定 Matlab Simulink仿真模型 1.模型简介 模型为感应(异步)电机矢量控制调速系统仿真,采用Matlab R2018a Simulink搭建
- CC2530无线zigbee裸机代码实现ADC采集内部温度并串口打印.zip
- CC2530无线zigbee裸机代码实现LED流水灯程序.zip
- CC2530无线zigbee裸机代码实现MQ-2气体传感器数值读取.zip
- CC2530无线zigbee裸机代码实现PWM调光控制.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈