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

📄 namerequest.java

📁 用JAVA写的一个小型聊天室的客户端
💻 JAVA
字号:
/**
 * Email: taorundong@126.com
 *
 * @author taorundong
 * @version 1.00 07/02/04
 */
 //This  class will restore your name first!
 import javax.swing.*;
 import java.awt.event.*;
 import java.awt.*;
 
 public class NameRequest extends JDialog implements ActionListener{
 	
 	private
 	static String name = null;//your name is fixed
 	JButton sure = null;
 	JPanel panel = null;
 	JTextField text = null;
 	
 	
 	NameRequest(){
 		super();
 		this.addWindowListener(new WindowAdapter(){
 			public void windowClosing(WindowEvent e){
 				dispose();
 				System.exit(0);
 			}
 		});
 		
 		sure = new JButton("OK");
 		sure.addActionListener(this);
 		panel = new JPanel();
 		text = new JTextField("Input your name here",20);
 		showWindow();
 		
 	}
 	
 	
	public void showWindow(){
		
		//checkResource();
		Dimension screen = this.getToolkit().getScreenSize();
		this.setBounds((screen.width/2-150),(screen.height/2-100),300,200);
		this.setResizable(false);
		
		panel.setLayout(new BorderLayout());
		JLabel label = new JLabel();
		label.setIcon(new ImageIcon("picture\\1.jpg"));
		JLabel imageLabel = new JLabel();
		imageLabel.setIcon(new ImageIcon("picture\\4.jpg"));
		
		JPanel textPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		textPanel.setBackground(Color.orange);
		textPanel.add(new JLabel("Name:  "));
		text.setEditable(true);
		text.setToolTipText("Please input your name here");
		text.setBackground(Color.yellow);
		text.addActionListener(this);
		textPanel.add(text);
		
		panel.add(textPanel,"North");
		panel.add(label,"Center");
		panel.add(imageLabel,"East");
		panel.add(sure,"South");
		panel.validate();
		
		this.add(panel);
		this.setVisible(true);
		this.validate();
	}
	
	
	static public String getClientName(){
		return name;
	}
	
	
	static public void setClientName(String s){
		name = s;
	}
	
	
	public void actionPerformed(ActionEvent e){
		if((e.getSource()==sure||e.getSource()==text)&&text.getText().length()!=0){

			//Send the name here
			setClientName(text.getText());
		//	System.out.println(name);//test the name input
			try{
				Thread.sleep(1000);
			}
			catch(Exception ee){
				ee.printStackTrace();
			}
			this.dispose();
			
			new Test("Client");
		}
		
		else{
		}
	}
	
	
	public static void main(String args[]){
		new NameRequest();
	}
	
	
 }

⌨️ 快捷键说明

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