码迷,mamicode.com
首页 > 编程语言 > 详细

day 5 : update QQReg & QQServer.java

时间:2016-10-26 22:06:37      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:ide   one   null   ram   log   oncommand   setfont   print   按钮   

技术分享

import java.awt.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
import java.awt.event.*;

public class QQReg extends JFrame implements ActionListener{
    public static void main(String[] args){
        QQReg w = new QQReg();
        w.setVisible(true);
    }
    
    JTextField txtUser = new JTextField();
    JPasswordField txtPass = new JPasswordField();
    JPasswordField txtPassRe = new JPasswordField();
    QQReg(){
        //设置窗体的基本信息
        this.setSize(660 , 380);
        this.setLocationRelativeTo(null);
        this.setTitle("Talking.GHOUL.Reg");
        this.setResizable(false);
        this.setIconImage(this.getToolkit().getImage("D:/lab_2/psb (11).jpg"));
        //new组件&设置组件
        JLabel labTitle = new JLabel("  SIGN UP  ");
        labTitle.setFont(new Font("", 0, 36));
        
        JLabel labUser = new JLabel("  Username");
        labUser.setFont(new Font("", 0, 30));
        JLabel labPass = new JLabel("  Password");
        labPass.setFont(new Font("", 0, 30));
        JLabel labPassRe = new JLabel("  Confirm Password");
        labPassRe.setFont(new Font("", 0, 30));
        
        //------update-----------------------
        //JComboBox cmbUsername = new JComboBox();
        //cmbUsername.setFont(new Font("", 0, 30));
        //cmbUsername.addItem("かねき けん");
        //cmbUsername.addItem("Kaneki Ken");
        //cmbUsername.addItem("金木 研");
        txtUser.setFont(new Font("", 0, 30));
        
        txtPass.setFont(new Font("", 0, 25));
        txtPassRe.setFont(new Font("", 0, 25));
        
        JButton btnReg = new JButton(" CONFIRM ");
        btnReg.setFont(new Font("", 0, 30));
        //注册事件监听
        btnReg.addActionListener(this);
        
        //布置主面板
        JPanel panUser = new JPanel();
        panUser.setLayout(new GridLayout(3 , 3));
        
        panUser.add(labUser);
        panUser.add(txtUser);
        panUser.add(labPass);
        panUser.add(txtPass);
        panUser.add(labPassRe);
        panUser.add(txtPassRe);
        //布置按钮面板
        JPanel panButton = new JPanel();
        panButton.setLayout(new FlowLayout());
        
        panButton.add(btnReg);
        //布置窗体
        this.setLayout(new BorderLayout());
        
        this.add(labTitle , BorderLayout.NORTH);
        this.add(panUser , BorderLayout.CENTER);
        this.add(panButton , BorderLayout.SOUTH);
    }
    
    @Override
    public void actionPerformed(ActionEvent arg0){
        //System.out.println(arg0);
        if(arg0.getActionCommand().equals(" CONFIRM ")){
            try{
                String user = txtUser.getText();
                String pass = txtPass.getText();
                Socket s = new Socket("127.0.0.1" , 8000);
            
                OutputStream os = s.getOutputStream();
                OutputStreamWriter osw = new OutputStreamWriter(os);
                PrintWriter pw = new PrintWriter(osw , true);
            
                pw.println(user+"%"+ pass);
            }catch(Exception e){}
        }
    }
}
import java.io.*;
import java.net.*;

public class QQServer{
    public static void main(String[] args){
        try{
            //监听8000端口
            ServerSocket ss = new ServerSocket(8000);
            
            System.out.println("等待客户端的消息...");
            Socket s = ss.accept();
            
            //接受用户名和密码
            InputStream is = s.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            
            String uandp = br.readLine();
            
            //检验点
            System.out.println(uandp);
        }catch(Exception e){}
    }
}

 

day 5 : update QQReg & QQServer.java

标签:ide   one   null   ram   log   oncommand   setfont   print   按钮   

原文地址:http://www.cnblogs.com/xkxf/p/6001991.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!