⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registerwindow.java

📁 一个自己用JAVA写的聊天程序,希望对大家游泳
💻 JAVA
字号:
package liaotian;/* * RegisterWindow.java * * Created on 2006年11月12日, 下午5:27 * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. *//** * * @author xingwang */import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.*;import java.sql.*;import java.io.*;import java.net.*;public class RegisterWindow extends JDialog implements ActionListener {        DataOutputStream out;	DataInputStream in;        Socket sock;	JPanel p1 = new JPanel();	JPanel p2 = new JPanel();	JPanel p3 = new JPanel();	JPanel p4 = new JPanel();	JPanel p5 = new JPanel();	//JPanel p6 = new JPanel();	JTextField txtUserNumber = new JTextField(15);	JTextField txtUserName = new JTextField(15);	JTextField txtUserSex = new JTextField(2);	JPasswordField txtPassWord = new JPasswordField(10);	JButton ok = new JButton("注册");	JButton cancel = new JButton("取消");	public RegisterWindow() {		setModal(true);		setBackground(Color.LIGHT_GRAY);		Container contentPane = this.getContentPane();		contentPane.setLayout(new GridLayout(6,1));		//p2.add(new JLabel("注册号:"));		//p2.add(txtUserNumber);		p2.add(new JLabel("昵称:   "));		p2.add(txtUserName);		p3.add(new JLabel("性别"));		p3.add(txtUserSex);		p3.add(new JLabel("密 码:"));		p3.add(txtPassWord);		p4.add(ok);		p4.add(cancel);		ok.addActionListener(this);		cancel.addActionListener(this);		txtUserNumber.addActionListener(this);		txtUserName.addActionListener(this);		txtUserSex.addActionListener(this);		txtPassWord.addActionListener(this);		contentPane.add(p1);		contentPane.add(p2);		contentPane.add(p3);		contentPane.add(p4);		contentPane.add(p5);		//contentPane.add(p6);		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);		setSize(350,270);		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();		setLocation((screen.width-300)/2,(screen.height-200)/2);		setTitle("注册窗口");		setResizable(false);		setVisible(true);	}	public void actionPerformed(ActionEvent e) {            if(e.getSource() == ok) {                if(txtUserName.getText().equals("") || txtPassWord.getText().equals("")){                  JOptionPane.showMessageDialog(null, "请输入用户名和密码!!!");                  }                else{                      try {				sock = new Socket("127.0.0.2",6000);				OutputStream os = sock.getOutputStream();				out = new DataOutputStream(os);				InputStream is = sock.getInputStream();				in = new DataInputStream(is);				//CCommunion th = new CCommunion(this);				//th.start();			    }catch(IOException ee) {				JOptionPane.showMessageDialog(null,"连接服务器失败!");				return;			}			//if(! txtUserName.getText().equals("")&&!txtPassWord.getText().equals("")&&!txtUserSex.getText().equals("")) {			if(!txtUserName.getText().equals("")){				try {					out.writeUTF("@reg");					out.writeUTF(txtUserName.getText());                    out.writeUTF(txtUserSex.getText());                    out.writeUTF(txtPassWord.getText());                   //in.readInt();                    JOptionPane.showMessageDialog(null, "欢迎注册!您的注册号是"  +in.readInt());                    sock.close();					//t1.append("客户说:" + t2.getText() + "\n");				} catch(Exception ee) {}                dispose();                new LoginWindow();            }		}                            }              		else if(e.getSource()== cancel) {			dispose();			System.exit(0);		}		else if(e.getSource() == txtUserName) {			txtPassWord.requestFocus();		}	}	public static void main(String args[]) {				new RegisterWindow();	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -