?? 好友界面.java
字號(hào):
continue;
}
if(Information.startsWith("New")){ //新加的好友列入好友名單
System.out.println("接到New");
if(Information.substring(3,4).equals("1")){
WhoIsOnLine=WhoIsOnLine+Information.substring(5,14)+"#";
}
Friend=Friend+Information.substring(4);
FriendList.clear();
SetFriendList();
continue;
}
if(Information.startsWith("Pass")){
if(Information.substring(4).equals("T")){
JOptionPane.showMessageDialog(null,"恭喜!修改密碼成功","恭喜",JOptionPane.INFORMATION_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null,"遺憾!修改密碼失敗","遺憾",JOptionPane.INFORMATION_MESSAGE);
}
continue;
}
if(Information.startsWith("Member")){
RequireByFindMember=Information.substring(6);
continue;
}
if(Information.startsWith("newGroup")){
if(Information.startsWith("newGroupOK")){
JOptionPane.showMessageDialog(null,"恭喜!建群成功","恭喜",JOptionPane.INFORMATION_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null,"遺憾!建群失敗","遺憾",JOptionPane.INFORMATION_MESSAGE);
}
}
if(Information.startsWith("ReplyToRequestGroupMember")){
RequireByGroups=Information.substring(25);
System.out.println("成員列表"+RequireByGroups);
}
if(Information.startsWith("TransFile")){
String Number=Information.substring(9,18);
String Port=Information.substring(18,22);
String Address=Information.substring(22);
String Name=私聊界面.FindNickName(Number);
int selected=JOptionPane.showConfirmDialog(null,Name+"要給您傳文件,接收?","消息",JOptionPane.YES_NO_OPTION);
if(selected==0){
SaveFile(Address);
}
else{
new SendAndReceive(Client_Socket,"ReTransFileRefuse").SendMessage();
}
}
if(Information.startsWith("ReTransFileFail")||Information.startsWith("ReTransFileRefuse")){
JOptionPane.showMessageDialog(null,"對(duì)方拒絕接受或不在線!","遺憾",JOptionPane.INFORMATION_MESSAGE);
私聊界面.TransFile.interrupt();
}
if(Information.startsWith("ChatRecordC")){
PrivateChatRecord=Information.substring(11);
System.out.println("聊天記錄"+PrivateChatRecord);
}
if(Information.startsWith("ChatRecordG")){
GroupChatRecord=Information.substring(11);
System.out.println("聊天記錄"+GroupChatRecord);
}
if(Information.startsWith("GroupMessage")) //好友發(fā)來的信息
{
String Group=Information.substring(12,16);
//String Speaker=Information.substring(16,20);
String Message=Information.substring(16);
System.out.println("發(fā)來的群消息:"+Message);
int i=0;
flag0=true;
boolean IsOnChat=false;
for(i=0;i<好友界面.GroupMessage.GetLength();i++){
if( this.GroupMessage.GetMember(i).GetSender().equals(Group)){
System.out.println("錯(cuò)在這里");
this.GroupMessage.GetMember(i).SetMessage(Message);
int j=0;
for(j=0;j<Groups.size();j++){
JLabel lab=(JLabel) 群.getModel().getElementAt(j);
String s=lab.getText();
if(s.equals(Group)){
this.群.setSelectedIndex(j);
break;
}
}
IsOnChat=true;
break;
}
}
if(!IsOnChat){
this.GroupMessage.AddNewMember(Group,Message);
int j=0;
for(j=0;j<Groups.size();j++){
JLabel lab=(JLabel) 群.getModel().getElementAt(j);
String s=lab.getText();
if(s.equals(Group)){
this.群.setSelectedIndex(j);
break;
}
}
flag0=false;
}
continue;
}
} catch (IOException ex) {
ex.printStackTrace();
continue;
}
}
}
public void SaveFile(String Addr){
String Address=Addr;
JFileChooser fc = new JFileChooser();
int result = fc.showSaveDialog(好友界面.this);
File file1 = fc.getSelectedFile();
String fileName = file1.getAbsolutePath();
System.out.println("fileName:"+fileName);
if (result == JFileChooser.APPROVE_OPTION){
try{
File file2=new File(fileName);
file2.createNewFile();
RandomAccessFile raf=new RandomAccessFile(file2,"rw");
// 通過Socket連接文件服務(wù)器
Socket server=new Socket(Address,7777);
//創(chuàng)建網(wǎng)絡(luò)接受流接受服務(wù)器文件數(shù)據(jù)
InputStream netIn=server.getInputStream();
InputStream in=new DataInputStream(new BufferedInputStream(new ProgressMonitorInputStream(this,"Reading ",netIn)));
//創(chuàng)建緩沖區(qū)緩沖網(wǎng)絡(luò)數(shù)據(jù)
byte[] buf=new byte[2048];
int num=in.read(buf);
System.out.println("in.read(buf)′length="+num);
while(num!=(-1)) {//是否讀完所有數(shù)據(jù)
raf.write(buf,0,num);//將數(shù)據(jù)寫往文件
raf.skipBytes(num);//順序?qū)懳募止?jié)
num=in.read(buf);//繼續(xù)從網(wǎng)絡(luò)中讀取文件
}
in.close();
raf.close();
}
catch(Exception ex){
System.out.println(ex);
}
}
if(result == JFileChooser.CANCEL_OPTION){
}
}
public void actionPerformed(ActionEvent e) {
System.out.println("點(diǎn)擊了右鍵鼠標(biāo)處理");
java.awt.datatransfer.Clipboard clipbd =new java.awt.datatransfer.Clipboard("");
String command = e.getActionCommand();
if(command.equalsIgnoreCase("上線")){
System.out.println("點(diǎn)擊了右鍵上線處理");
PrintWriter GoOut;
try {
GoOut = new PrintWriter(Client_Socket.getOutputStream());
GoOut.println("6"+QQNumber);
GoOut.flush();
State="1";
狀態(tài).setText("在線");
頭像.setEnabled(true);
} catch (IOException ex) {
ex.printStackTrace();
}
}
else if(command.equalsIgnoreCase("隱身")){
System.out.println("點(diǎn)擊了右鍵隱身處理");
PrintWriter GoOut;
try {
GoOut = new PrintWriter(Client_Socket.getOutputStream());
GoOut.println("7"+QQNumber);
GoOut.flush();
State="0";
狀態(tài).setText("隱身");
頭像.setEnabled(false);
} catch (IOException ex) {
ex.printStackTrace();
}
}
else if(command.equalsIgnoreCase("下線")){
System.out.println("點(diǎn)擊了右鍵下線處理");
頭像.setEnabled(false);
PrintWriter GoOut;
try {
GoOut = new PrintWriter(Client_Socket.getOutputStream());
GoOut.println("5"+QQNumber);
GoOut.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
this.dispose();
}
}
private JPopupMenu getJPopupMenu(){
jPopupMenu = new JPopupMenu();
jPopupMenu.add(getOnMenuItem());
jPopupMenu.add(getHideMenuItem());
jPopupMenu.add(getOffMenuItem());
return jPopupMenu;
}
private JMenuItem getOnMenuItem() {
JMenuItem OnMenuItem = new JMenuItem();
OnMenuItem.setText("上線");
OnMenuItem.addActionListener(this);
return OnMenuItem;
}
private JMenuItem getHideMenuItem() {
JMenuItem HideMenuItem = new JMenuItem();
HideMenuItem.setText("隱身");
HideMenuItem.addActionListener(this);
return HideMenuItem;
}
private JMenuItem getOffMenuItem() {
JMenuItem OffMenuItem = new JMenuItem();
OffMenuItem.setText("下線");
OffMenuItem.addActionListener(this);
return OffMenuItem;
}
// 變量聲明 - 不進(jìn)行修改//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JButton 個(gè)人設(shè)置;
private javax.swing.JLabel 頭像;
private javax.swing.JLabel 好友標(biāo)簽;
private javax.swing.JList 好友欄;
private javax.swing.JPanel 容器;
private javax.swing.JButton 查找;
private javax.swing.JLabel 狀態(tài);
private javax.swing.JList 群;
// 變量聲明結(jié)束//GEN-END:variables
private Socket Client_Socket=null;
private javax.swing.JLabel FriendLabel=null;
public static ObjectArray InforList=null;
public static ObjectArray GroupMessage=null;
private String QQNumber=null;
private Vector FriendList=null;
private Vector Groups=null;
private boolean flag=false;
private boolean flag0=false;
private ImageIcon[] ImageArray=null;
private String NickName=null;
private String TrueName=null;
private String Sex=null;
private String Age=null;
private String LeavingMessage=null;
private String Icon=null;
private String Sign=null;
public static String Friend=null;
private String OnlineTime=null;
private String RequestList=null;
private String ResponseList=null;
public static String GroupList=null;
public static String MyGroup=null;
private String Message=null;
private String GroupLeavingMessage=null;
private String WhoIsOnLine=null;
private String State=null;
private JPopupMenu jPopupMenu;
public static String RequireByFindFriend=null;
public static String RequireByFindMember=null;
public static String QQPassword=null;
public static String RequireByGroups=null;
public static String PrivateChatRecord=null;
public static String GroupChatRecord=null;
private AudioClip MsgSound=null;
}
/*class CellRender extends JLabel implements ListCellRenderer{
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
String s = value.toString();
setText(s);
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
}
else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
setEnabled(list.isEnabled());
setFont(list.getFont());
setOpaque(true);
return this;
}
}*/
class MyListCellRenderer implements ListCellRenderer {
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus){
JLabel lbl = (JLabel)value;
lbl.setOpaque(true);
lbl.setBackground(isSelected ? Color.green : Color.white);
lbl.setForeground(isSelected ? Color.white : Color.YELLOW);
return lbl;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -