Java初学简易聊天Word文档下载推荐.docx
- 文档编号:15928508
- 上传时间:2022-11-17
- 格式:DOCX
- 页数:21
- 大小:19.09KB
Java初学简易聊天Word文档下载推荐.docx
《Java初学简易聊天Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《Java初学简易聊天Word文档下载推荐.docx(21页珍藏版)》请在冰豆网上搜索。
try
if(newFile("
flag.txt"
).exists())
raf=newRandomAccessFile("
"
r"
);
i=raf.readInt();
raf.close();
}
else
i=0;
i++;
raf=newRandomAccessFile("
rw"
raf.writeInt(i);
}
catch(Exceptione1)
e1.printStackTrace();
}
//创建新框架
aQQFrame=newQQFrame();
aQQFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
aQQFrame.setVisible(true);
//关闭按钮时更改flag.txt信息
aQQFrame.addWindowListener(newWindowAdapter()
{
publicvoidwindowClosing(WindowEvente)
RandomAccessFileraf;
if(newFile("
{
raf=newRandomAccessFile("
}
else
i=1;
}
i--;
raf=newRandomAccessFile("
}
catch(Exceptione1)
e1.printStackTrace();
}
System.exit(0);
});
}
});
publicstaticQQFramegetQQFrame()
returnaQQFrame;
publicstaticintgetI()
returni;
}
classQQFrameextendsJFrame
privateSetDialogdialog;
privateQQPanelaQQPanel;
publicQQFrame()
//获取屏幕大小,设置框架
Toolkitkit=Toolkit.getDefaultToolkit();
DimensionScreenSize=kit.getScreenSize();
intHeight=ScreenSize.height;
intWidth=ScreenSize.width;
setBounds(Width/3,Height/8,Width/3,(Height*2)/3);
setTitle("
MyQQ"
//菜单栏
JMenuBarmenuBar=newJMenuBar();
this.setJMenuBar(menuBar);
JMenusystem=newJMenu("
系统"
menuBar.add(system);
JMenuItemitemSet=newJMenuItem("
设置"
JMenuItemitemExit=newJMenuItem("
退出"
system.add(itemSet);
system.add(itemExit);
//创建设置对话框
try
dialog=newSetDialog(MyQQ.getQQFrame());
}
catch(Exceptione)
e.printStackTrace();
}
//退出监听器
itemExit.addActionListener(newActionListener()
publicvoidactionPerformed(ActionEventevent)
System.exit(0);
//设置监听器
itemSet.addActionListener(newActionListener()
dialog.setTextField();
dialog.setVisible(true);
//添加面板
aQQPanel=newQQPanel(2*(Height/3),Width/3);
add(aQQPanel);
publicQQPanelgetQQPanel()
returnaQQPanel;
publicSetDialoggetSetDialog()
returndialog;
classQQPanelextendsJPanel
privateinty;
privateintx;
privateJLabelnameLabel=newJLabel("
昵称:
"
privateJTextFieldnameText=newJTextField();
privateJTextAreaRecord=newJTextArea();
privateJTextAreaWords=newJTextArea();
privateJScrollPaneRScrollPane=newJScrollPane(Record);
privateJScrollPaneWScrollPane=newJScrollPane(Words);
privateJButtonsendButton=newJButton("
传送文件"
privateJButtonacceptButton=newJButton("
接收文件"
privateJButtonmessageButton=newJButton("
发送"
privateStringgetWords="
;
privateFilesendFile=null;
privateFileacceptFile=null;
privateStringacceptPath="
publicQQPanel(intheight,intwidth)
y=height/32;
x=width/32;
setLayout(null);
RScrollPane.setBounds(0,0,width,13*y);
WScrollPane.setBounds(0,15*y,width,9*y);
nameLabel.setBounds(1*x,13*y,4*x,2*y);
nameText.setBounds(4*x,13*y,width-4*x,2*y);
sendButton.setBounds(3*x,25*y,8*x,2*y);
acceptButton.setBounds(12*x,25*y,8*x,2*y);
messageButton.setBounds(23*x,24*y,8*x,3*y);
Record.setEditable(false);
acceptButton.setEnabled(false);
//发送消息按钮监听器
messageButton.addActionListener(newActionListener()
publicvoidactionPerformed(ActionEvente)
getWords="
if((getWords=Words.getText())!
="
)
SocketclientSocket=null;
PrintWriterout=null;
clientSocket=newSocket(MyQQ.getQQFrame().getSetDialog().getIP(),Integer.parseInt(MyQQ.getQQFrame().getSetDialog().getTxtSend()));
out=newPrintWriter(clientSocket.getOutputStream());
Stringtemp=nameText.getText()+"
:
+getWords+"
\n"
out.println(temp);
out.close();
clientSocket.close();
Record.append(temp);
Words.setText("
}
catch(Exceptione1)
});
//文件传送
classStartSendFileextendsThread
publicvoidrun()
sendFile=ShowOpenDialog.ShowOpenDialog(true);
if(sendFile!
=null)
OutputStreamops=null;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 初学 简易 聊天