📄 personalchat.java
字号:
}
/**
* This method initializes otherPanelR
*
* @return javax.swing.JPanel
*/
private JPanel getOtherPanelR() {
if (otherPanelR == null) {
otherPanelR = new JPanel();
otherPanelR.setLayout(new BorderLayout());
otherPanelR.add(getJScrollPane1(), BorderLayout.EAST);
}
return otherPanelR;
}
/**
* This method initializes chatNotesTextPane
*
* @return javax.swing.JTextPane
*/
public JTextPane getChatNotesTextPane() {
if (chatNotesTextPane == null) {
chatNotesTextPane = new MyTextPane();
}
return chatNotesTextPane;
}
/**
* This method initializes chatMegScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getChatMegScrollPane() {
if (chatMegScrollPane == null) {
chatMegScrollPane = new JScrollPane();
chatMegScrollPane.setViewportView(getChatNotesTextPane());
}
return chatMegScrollPane;
}
/**
* This method initializes saveChatNotes
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getSaveChatNotes() {
if (saveChatNotes == null) {
saveChatNotes = new JMenuItem();
saveChatNotes.setText("保存记录");
saveChatNotes.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
InputEvent.CTRL_DOWN_MASK,true));
saveChatNotes.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
getSaveChooser();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
});
}
return saveChatNotes;
}
private JFileChooser getSaveChooser() throws FileNotFoundException{
///保存聊天信息内容
saveChooser = new JFileChooser();
int result = saveChooser.showSaveDialog(this);
if(result == JFileChooser.APPROVE_OPTION){
saveNotes = chatNotesTextPane.getText();
File saveFile = saveChooser.getSelectedFile();
FileOutputStream save = new FileOutputStream(saveFile);
try {
save.write(saveNotes.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
return saveChooser;
}
/**
* This method initializes jList
* @return javax.swing.JList
*/
private MyList getJList() {
if (jList == null) {
jList = new MyList();
jList.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
if (e.getClickCount() == 2) {//双击
int imageIndex = jList.getSelectedIndex();
jList.iconListItem =
(IconListItem)jList.getModel().getElementAt(imageIndex);
if(clientSocket!=null){
try {
dataOut.writeObject("表情");
dataOut.flush();
dataOut.writeObject(jList.iconListItem.getIcon());
dataOut.flush();
} catch (IOException ex) {
JOptionPane.showMessageDialog(null,"发送表情错误",
"系统警告",JOptionPane.WARNING_MESSAGE);
ex.printStackTrace();
}
}
}
}
});
jList.setIcon("mood/4.gif", "流口水");
jList.setIcon("mood/9.gif", "寒");
jList.setIcon("mood/2.gif", "拍砖");
jList.setIcon("mood/11.gif","哭泣");
jList.setIcon("mood/12.gif", "生气");
jList.setIcon("mood/13.gif", "口水");
jList.setIcon("mood/14.gif", "汗");
jList.setIcon("mood/15.gif", "笑");
jList.setIcon("mood/16.gif", "惊讶");
jList.setIcon("mood/17.gif", "崇拜");
jList.setIcon("mood/18.gif", "不可思议");
jList.setIcon("mood/19.gif", "害怕");
jList.setIcon("mood/20.gif", "大鼻孔");
jList.setIcon("mood/21.gif", "害羞");
jList.setIcon("mood/22.gif", "不屑一顾");
jList.setIcon("mood/25.gif","泪人");
jList.setIcon("mood/26.gif","砸人");
jList.setIcon("mood/27.gif", "亲热");
jList.setIcon("mood/28.gif","噢!耶");
jList.setIcon("mood/34.gif","崇拜");
}
return jList;
}
/**
* This method initializes jScrollPane1
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane1() {
if (jScrollPane1 == null) {
jScrollPane1 = new JScrollPane();
jScrollPane1.setViewportView(getJList());
}
return jScrollPane1;
}
/**
* This method initializes clearItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getClearItem() {
if (clearItem == null) {
clearItem = new JMenuItem("清空文本");
clearItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,
InputEvent.ALT_MASK,true));
clearItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
recevTextPane.setText("");
}
});
}
return clearItem;
}
/**
* This method initializes exitItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getExitItem() {
if (exitItem == null) {
exitItem = new JMenuItem("退出");
exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
InputEvent.ALT_MASK,true));
exitItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
exit();
IMPanelClient.isClick=false;
}
});
}
return exitItem;
}
private void exit(){
if(clientSocket == null){
dispose();
IMPanelClient.isClick=false;
}
if(clientSocket != null&&!clientSocket.isClosed()){
try {
dataOut.writeObject("退出私聊");
dataOut.flush();
dispose();
jList2.removeAllElements();
jList2.addString("秘密会谈中:)");
IMPanelClient.isClick=false;
} catch (IOException e1) {
e1.printStackTrace();
}
}else{
dispose();
}
}
/**
* This method initializes phonePanel
*
* @return javax.swing.JPanel
*/
private JPanel getPhonePanel() {
if (phonePanel == null) {
phonePanel = new JPanel();
phonePanel.setLayout(new BorderLayout());
phonePanel.add(getSendButton(), BorderLayout.NORTH);
phonePanel.add(getExit(), BorderLayout.EAST);
phonePanel.add(getMsgScrollPane(), BorderLayout.CENTER);
}
return phonePanel;
}
/**
* This method initializes exit
*
* @return javax.swing.JButton
*/
private JButton getExit() {
if (exit == null) {
exit = new JButton();
exit.setText("结束");
exit.setToolTipText("结束语音聊天请求");
exit.setCursor(new Cursor(Cursor.HAND_CURSOR));
exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
//VoiceThread VT = new VoiceThread();
//VT.isOver = true;
//VT.interrupt();
//ClientReceiveThread.isOver = true;
//voiceTextPane.append(Color.lightGray,"已经成功退出语音…………\n");
}
});
}
return exit;
}
/**
* This method initializes sendButton
*
* @return javax.swing.JButton
*/
private JButton getSendButton() {
if (sendButton == null) {
sendButton = new JButton();
sendButton.setText("呼叫");
sendButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
sendButton.setUI(new MetalButtonUI());
sendButton.setToolTipText("发送语音聊天请求");
sendButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
//开始等待对方的语音数据
//startPhone();
}
});
}
return sendButton;
}
/* private void catchVoice() throws IOException{
int b = 0;
int bufSize = 1024*5;
byte[] compressedVoice = new byte[bufSize];
InputStream myIStream = null;
myIStream = PhoneMIC.getAudioInputStream();
while((!Thread.currentThread().interrupted()))
b = myIStream.read(compressedVoice,0, bufSize);
//发送标示符
dataOut.writeObject("语音数据");
dataOut.flush();
System.out.print("ewewewew");
dataOut.write(compressedVoice,0,b);
dataOut.flush();
}
*/
/**
* This method initializes msgScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getMsgScrollPane() {
if (msgScrollPane == null) {
msgScrollPane = new JScrollPane();
msgScrollPane.setViewportView(getVoiceTextPane());
}
return msgScrollPane;
}
/**
* This method initializes voiceTextPane
*
* @return com.gamvan.club.users.im.tools.MyTextPane
*/
public MyTextPane getVoiceTextPane() {
if (voiceTextPane == null) {
voiceTextPane = new MyTextPane();
}
return voiceTextPane;
}
/**
* @param args
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
thisClass = new PersonalChat();
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public PersonalChat() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
public void initialize() {
this.setSize(600,400);
this.setJMenuBar(getJJMenuBar());
this.setContentPane(getJContentPane());
this.setTitle("GamVanTalk(Personal)");
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
exit();
}
});
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BoxLayout(getJContentPane(), BoxLayout.X_AXIS));
jContentPane.add(getJTabbedPane(), null);
}
return jContentPane;
}
} // @jve:decl-index=0:visual-constraint="10,10"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -