黑马程序员技术交流社区

标题: 聊天系统,服务器端Server(一) [打印本页]

作者: 王鑫宇    时间: 2011-8-4 18:24
标题: 聊天系统,服务器端Server(一)
1.ClientShowMyInfo类[code=java]package util.doTask;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;

import javax.swing.*;

import util.ClientMainWindow;


public class ClientShowMyInfo extends ClientMainWindow {
       
        private JPanel pane;
        private JLabel nickName;
        private JLabel sex;
        private JLabel age;
        private JLabel birthday;
        private JLabel birthday_1;
        private JLabel birthday_2;
        private JLabel trueName;
        private JLabel address;
        private JLabel description;
        private JLabel sign;
        private JTextField nickName_value;
        private ButtonGroup bg;
        private JRadioButton sex_value_1;
        private JRadioButton sex_value_2;
        private JTextField age_value;
        private JTextField birthday_value1;
        private JTextField birthday_value2;
        private JTextField trueName_value;
        private JTextField address_value;
        private JTextField description_value;
        private JTextField sign_value;
        private JButton submit;
        private JButton shut;
        private JButton exit;

        public ClientShowMyInfo(){
                MyInfoInit();
        }
       
        public void MyInfoInit(){
                this.setBounds(260,150,400,300);
                this.setLayout(null);
                this.setTitle(mySecondName+" -  个人资料");
                this.addWindowListener(new WindowAdapter(){
                        public void windowClosing(WindowEvent e) {
                                exit();
                        }
                });
               
                pane = new JPanel();
                pane.setBounds(20,5,320,270);
                pane.setLayout(new FlowLayout(3,5,20));
                this.add(pane);
                nickName = new JLabel("呢称:");
                pane.add(nickName);
                nickName_value = new JTextField(10);
                pane.add(nickName_value);
                sex = new JLabel("  性别:");
                pane.add(sex);
                sex_value_1 = new JRadioButton("男");
                pane.add(sex_value_1);
                sex_value_2 = new JRadioButton("女");
                pane.add(sex_value_2);
                bg = new ButtonGroup();
                bg.add(sex_value_1);
                bg.add(sex_value_2);
                age = new JLabel("年龄:");
                pane.add(age);
                age_value = new JTextField(4);
                pane.add(age_value);
                birthday = new JLabel("生日:");
                pane.add(birthday);
                birthday_value1 = new JTextField(2);
                pane.add(birthday_value1);
                birthday_1 = new JLabel("月 ");
                pane.add(birthday_1);
                birthday_value2 = new JTextField(2);
                pane.add(birthday_value2);
                birthday_2 = new JLabel("日   ");
                pane.add(birthday_2);
                trueName = new JLabel("真实姓名:");
                pane.add(trueName);
                trueName_value = new JTextField(16);
                pane.add(trueName_value);
                address = new JLabel("所在地:");
                pane.add(address);
                address_value = new JTextField(40);
                pane.add(address_value);
                description = new JLabel("自我描述:");
                pane.add(description);
                description_value = new JTextField(40);
                pane.add(description_value);
                sign = new JLabel("个性签名:");
                pane.add(sign);
                sign_value = new JTextField(40);
                pane.add(sign_value);
                submit = new JButton(" 确 定 ");
                submit.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent arg0) {
                                String [] strs = new String[8];
                                String nickName = nickName_value.getText().trim();
                                strs[0] = nickName;
                                String sex="";
                                if(sex_value_1.isSelected()) sex=sex_value_1.getText();
                                if(sex_value_2.isSelected()) sex=sex_value_2.getText();
                                strs[1] = sex;
                                String age = age_value.getText().trim();
                                strs[2] = age;
                                String birthday = birthday_value1.getText().trim()+birthday_value2.getText().trim();
                                strs[3] = birthday;
                                String trueName = trueName_value.getText().trim();
                                strs[4] = trueName;
                                String address = address_value.getText().trim();
                                strs[5] = address;
                                String description = description_value.getText().trim();
                                strs[6] = description;
                                String sign = sign_value.getText().trim();
                                strs[7] = sign;
                                String msg = "";
                                for(int i = 0 ; i < 8 ; i++){
                                        if(strs==null){
                                                msg=msg+"0;";
                                                continue;
                                        }
                                        msg=msg+strs.length()+";"+strs;
                                }
                               
                                try {
                                        dos.writeUTF("g"+msg);
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        }
                });
                pane.add(submit);
                shut = new JButton(" 关 闭 ");
                shut.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent arg0) {
                                exit();
                        }
                });
                pane.add(shut);
//                exit = new JButton(" 取 消 ");
//                pane.add(exit);
               
                this.setVisible(true);
                this.validate();
               
        }
        public void msg(String msg){
                if(msg.equals("OK")){
                        JOptionPane.showMessageDialog(csmi, "更新成功");
                        //JOptionPane.showConfirmDialog(csmi,"更新成功","提示信息",0,1);
                        return;
                }
                if(msg.equals("NO")){
                        JOptionPane.showMessageDialog(csmi, "更新失败");
                        //JOptionPane.showConfirmDialog(csmi,"更新失败","提示信息",0,2);
                        return;
                }
        }
        public void setInfo(String msg){
                String temp=msg;
                String nickName = temp.substring(2,Integer.parseInt(String.valueOf(temp.charAt(0)))+2);
                nickName_value.setText(nickName);
                temp = temp.substring(Integer.parseInt(String.valueOf(temp.charAt(0)))+2);               
                String sex = temp.substring(2,Integer.parseInt(String.valueOf(temp.charAt(0)))+2);
                if(sex.equals("男")) sex_value_1.setSelected(true);
                if(sex.equals("女")) sex_value_2.setSelected(true);
                temp = temp.substring(Integer.parseInt(String.valueOf(temp.charAt(0)))+2);               
                String age = temp.substring(2,Integer.parseInt(String.valueOf(temp.charAt(0)))+2);
                age_value.setText(age);
                temp = temp.substring(Integer.parseInt(String.valueOf(temp.charAt(0)))+2);               
                String birthday = temp.substring(2,Integer.parseInt(String.valueOf(temp.charAt(0)))+2);
                if(!birthday.equals("")){
                        birthday_value1.setText(birthday.substring(0,2));
                        birthday_value2.setText(birthday.substring(2));
                }
                temp = temp.substring(Integer.parseInt(String.valueOf(temp.charAt(0)))+2);               
                String trueName = temp.substring(2,Integer.parseInt(String.valueOf(temp.charAt(0)))+2);
                trueName_value.setText(trueName);
                temp = temp.substring(Integer.parseInt(String.valueOf(temp.charAt(0)))+2);               
                String address = temp.substring(2,Integer.parseInt(String.valueOf(temp.charAt(0)))+2);
                address_value.setText(address);
                temp = temp.substring(Integer.parseInt(String.valueOf(temp.charAt(0)))+2);               
                String description = temp.substring(2,Integer.parseInt(String.valueOf(temp.charAt(0)))+2);
                description_value.setText(description);
                temp = temp.substring(Integer.parseInt(String.valueOf(temp.charAt(0)))+2);               
                String sign = temp.substring(2,Integer.parseInt(String.valueOf(temp.charAt(0)))+2);
                sign_value.setText(sign);
        }
        public void exit(){
                csmi = null ;
                this.dispose();
        }
       
       
}[/code]




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2