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

📄 loginwindow.java

📁 一个自己用JAVA写的聊天程序,希望对大家游泳
💻 JAVA
字号:
package liaotian;/* * LoginWindow.java * * Created on 2006年11月12日, 下午1:17 * * 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.io.*;import java.net.*;import java.awt.event.*;import javax.swing.*;public class LoginWindow 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();	JTextField txtUserName = new JTextField(15);	JPasswordField txtPassWord = new JPasswordField(15);	JButton ok = new JButton("确定");	JButton cancel = new JButton("取消");	public LoginWindow() {            		setModal(true);		setBackground(Color.LIGHT_GRAY);		Container contentPane = this.getContentPane();		contentPane.setLayout(new GridLayout(5,1));		p2.add(new JLabel("注册号:"));		p2.add(txtUserName);		p3.add(new JLabel("密 码:  "));		p3.add(txtPassWord);		p4.add(ok);		p4.add(cancel);		ok.addActionListener(this);		cancel.addActionListener(this);		txtUserName.addActionListener(this);		txtPassWord.addActionListener(this);		contentPane.add(p1);		contentPane.add(p2);		contentPane.add(p3);		contentPane.add(p4);		contentPane.add(p5);		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);		setSize(300,220);		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();		setLocation((screen.width-300)/2,(screen.height-220)/2);		setTitle("登录窗口");		setResizable(false);		setVisible(true);                	}	public void actionPerformed(ActionEvent e) {                             		if(e.getSource() == ok || e.getSource() == txtPassWord) {                                try {				sock = new Socket("10.1.190.135",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;			}                                try {                                        InetAddress address=InetAddress.getLocalHost();                                        String IP_name=address.getHostAddress();                                        String names=address.getHostName();					out.writeUTF("@logon");					out.writeUTF(txtUserName.getText());                                        out.writeUTF(txtPassWord.getText());                                        out.writeUTF(IP_name);                                        String strings=in.readUTF();                                       if(strings.equals("OK")){                                                new Client(sock);                                       }                                       else{                                            new LoginWindow();                                       }				} catch(Exception ee) {}                               dispose();                }		if(e.getSource()== cancel) {			dispose();			System.exit(0);		}		if(e.getSource() == txtUserName) {			txtPassWord.requestFocus();		}	}	public static void main(String args[]) {				new LoginWindow();	}}

⌨️ 快捷键说明

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