?? chatarea.java~970~
字號:
else {//發送消息為空
JOptionPane.showMessageDialog(null,
constant.getLang("CA_fsxxbnwk"),
constant.getLang("CA_tsxx"),
JOptionPane.WARNING_MESSAGE);
}
}
}
catch (BadLocationException bade) {}
catch (IOException e2) {
}
}
else if (e.getSource() == clearSendObjectButton) {
toPeople.removeAllElements();
selectNameSB.delete(0, selectNameSB.length());
sendObject.setText("");
}
else if (e.getSource() == sendFile) {//發送文件
if (selectNameSB.length() <= 0) {//沒有選擇發送對象
JOptionPane.showMessageDialog(null, constant.getLang("CA_qxxzfsdx"),
constant.getLang("CA_tsxx"),
JOptionPane.WARNING_MESSAGE);
}
else if (toPeople.contains("大家") || toPeople.contains(userName)) {//發送對象包含大家或者自己
JOptionPane.showMessageDialog(null,
constant.getLang("CA_fsdxbyxbhdjhzj"),
constant.getLang("CA_tsxx"),
JOptionPane.WARNING_MESSAGE);
}
else {
int state = chooser.showOpenDialog(null);//顯示文件選擇器
file = chooser.getSelectedFile();//取得用戶選擇的文件
if (file != null && state == (chooser.APPROVE_OPTION)) {//用戶選擇了文件并且點擊了確定
if (file.exists()) {//文件存在
ClientSendFile clientSendFile = new ClientSendFile(file, toPeople);
}
else {//文件不存在
JOptionPane.showMessageDialog(null,
constant.getLang("CA_wjbczhzsy"),
constant.getLang("CA_tsxx"),
JOptionPane.WARNING_MESSAGE);
}
}
}
}
else if (e.getSource() == loginOut) {//用戶退出
try {
int selected = JOptionPane.showConfirmDialog(ChatArea.this,
constant.getLang("CA_bcltjlm"), constant.getLang("CA_tsxx"),
JOptionPane.YES_NO_OPTION);//顯示保存記錄對話框
if (selected == JOptionPane.YES_OPTION) {//選擇確定
String userHome = System.getProperty("user.home");//取得用戶目錄
File fileDir = new File(userHome + "/聊天記錄", userName);//創建保存記錄文件夾
if (!fileDir.exists()) {//文件不存在
fileDir.mkdir();
}
File saveFile;
RandomAccessFile outputStream;
try {
saveFile = new File(fileDir, userName + "公共");//公共聊天記錄
outputStream = new RandomAccessFile(saveFile, "rw");
outputStream.seek(outputStream.length());
outputStream.write( (publicDoc.getText(0, publicDoc.getLength())).
getBytes());
outputStream.close();
}
catch (Exception e2) {
}
try {
saveFile = new File(fileDir, userName + "私人");//私人聊天記錄
outputStream = new RandomAccessFile(saveFile, "rw");
outputStream.seek(outputStream.length());
outputStream.write( (privateDoc.getText(0, privateDoc.getLength())).
getBytes());
outputStream.close();
}
catch (Exception e2) {
}
}
out.writeUTF("PRIVATEMESSAGELOG:" +
privateDoc.getText(0, privateDoc.getLength()));//上傳私人聊天記錄
Thread.sleep(5);
out.writeUTF("PUBLICMESSAGELOG:" +
publicDoc.getText(0, publicDoc.getLength()));//上傳公共聊天記錄
}
catch (Exception e2) {
}
if (socket != null) {//關閉資源
try {
socket.close();
out.flush();
out.close();
in.close();
}
catch (IOException ioe) {}
}
System.exit(0);
}
}
}
class RevertAction
implements ActionListener {//自動回復事件
public void actionPerformed(ActionEvent e) {
JMenuItem menuItem = (JMenuItem) e.getSource();
if (menuItem == quxiao) {//取消事件
REVERTOPTION = 0;
REVERTMESSAGE = null;
}
if (menuItem == zidingyi) {//自定義事件
String inputVaule = JOptionPane.showInputDialog(ChatArea.this,
constant.getLang("CA_srzdyxx"));//彈出輸入框
if (inputVaule != null && inputVaule.length() > 0) {//選擇確定,并且輸入消息
REVERTOPTION = 1;
REVERTMESSAGE = inputVaule;
}
else {
quxiao.setSelected(true);
REVERTOPTION = 0;
REVERTMESSAGE = null;
}
}
else {
REVERTOPTION = 1;
REVERTMESSAGE = menuItem.getText();
}
}
}
class ConsoleAction
implements ActionListener {//控制臺事件
public void actionPerformed(ActionEvent e) {
if (e.getSource() == consoleMenuItem) {
if (consoleMenuItem.isSelected()) {
CONSOLESTATE = 1;//設置標志位
}
else {
CONSOLESTATE = 0;
}
}
}
}
/**
*
* <p>Title: 聊天記錄事件內部類</p>
* <p>Description: 處理聊天記錄菜單項</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
class ChatLogAction
implements ActionListener {
public void actionPerformed(ActionEvent e) {
String s;
chatLogFile = null;
if (e.getSource() == chatLogPriMenuItem) {//查看私人聊天記錄
chatLogFile = new File(userHome + "/聊天記錄/" + userName,
userName + "私人");
}
else if (e.getSource() == chatLogPubMenuItem) {//查看公共聊天記錄
chatLogFile = new File(userHome + "/聊天記錄/" + userName,
userName + "公共");
}
else if (e.getSource() == chatLogCloseMenuItem) {//關閉查看面板
tablePane.remove(chatLogscrollPane);
chatLog.setText("");
}
if (chatLogPriMenuItem.isSelected() || chatLogPubMenuItem.isSelected()) {
if (chatLogFile.exists()) {//聊天記錄存在
try {
tablePane.addTab("", chatLogIconNew, chatLogscrollPane);
chatLog.setText("");
chatLogFileReader = new FileReader(chatLogFile);
chatLogBR = new BufferedReader(chatLogFileReader);
while ( (s = chatLogBR.readLine()) != null) {
chatLog.append(s + "\n");
}
}
catch (Exception e1) {
e1.printStackTrace();
}
}
else {
JOptionPane.showMessageDialog(null, constant.getLang("CA_myltjl"),
constant.getLang("CA_tsdhk"),
JOptionPane.WARNING_MESSAGE);
}
}
else {
tablePane.remove(chatLogscrollPane);
chatLog.setText("");
}
}
}
/**
*
* <p>Title:鍵盤時間內部類 </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
class keyBoardAction
implements KeyListener {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
if ( (e.getModifiers() & InputEvent.CTRL_MASK) != 0) {
String peoples = "";
try {
String content = messageEditor.getMessage().trim();
if (content.length() > 0 && selectNameSB.length() > 0) {
messageEditor.setMessage();
messageEditor.messageTextPane.setFocusable(true);
if (toPeople.contains("大家")) {
StringReader stringReader = new StringReader(
"<p><font color=\"#0080C0\">^您對大家說:^</font></p>" + content);
editorKit.read(stringReader, publicDoc, publicDoc.getLength());
if (CONSOLESTATE == 1) {
out.writeUTF("CONSOLE_PUBLIC_MESSAGE:" + "#MESSAGECONTENT#" +
content);
}
else {
out.writeUTF("PUBLIC_MESSAGE:" + "#MESSAGECONTENT#" + content);
}
}
else {
Enumeration enum = toPeople.elements();
while (enum.hasMoreElements()) {
peoples = peoples + enum.nextElement() + "$";
}
StringReader stringReader = new StringReader(
"<p><font color=\"#0080C0\">^您對" + selectNameSB +
"說:^</font></p>" + content);
editorKit.read(stringReader, privateDoc, privateDoc.getLength());
if (CONSOLESTATE == 1) {
out.writeUTF("CONSOLE_PRIVATE_MESSAGE:" + "#TOPEOPLE#" +
peoples + "#MESSAGECONTENT#" + content);
}
else {
out.writeUTF("PRIVATE_MESSAGE:" + "#TOPEOPLE#" + peoples +
"#MESSAGECONTENT#" + content);
}
}
}
else {
if (selectNameSB.length() <= 0) {
JOptionPane.showMessageDialog(null,
constant.getLang("CA_qxxzfsdx"),
constant.getLang("CA_tsxx"),
JOptionPane.WARNING_MESSAGE);
}
else {
JOptionPane.showMessageDialog(null,
constant.getLang("CA_fsxxbnwk"),
constant.getLang("CA_tsxx"),
JOptionPane.WARNING_MESSAGE);
}
}
}
catch (BadLocationException bade) {}
catch (IOException e2) {
}
}
}
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
}
class TablePaneAction
implements MouseListener {
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
JTabbedPane tablePane = (JTabbedPane) e.getSource();
if (tablePane.getSelectedIndex() == 0) {
tablePane.setIconAt(0, publicTableIcon);
}
if (tablePane.getSelectedIndex() == 1) {
tablePane.setIconAt(1, privateTableIcon);
}
if (tablePane.getSelectedIndex() == 2) {
tablePane.setIconAt(2, fileTableIcon);
}
if (tablePane.getSelectedComponent() == chatLogscrollPane) {
tablePane.setIconAt(tablePane.getSelectedIndex(), chatLogIcon);
}
}
}
public static void centerOnScreen(Window window) {
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
window.setLocation( (d.width - window.getWidth()) / 2,
(d.height - window.getHeight()) / 2);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -