name_input.java

来自「软件工程实践课程的答案哦」· Java 代码 · 共 54 行

JAVA
54
字号
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Name_Input extends JDialog implements ActionListener
{
	private JTextField text;
	private JButton confirm;
	private GameFace face;
	
	public Name_Input(GameFace face)
	{
		setTitle(
		"Please Enter Player Name:");
		    
		                              
		          
		                            
		this.face=face;
		
		Container c=getContentPane();
		c.setLayout(new FlowLayout());
		
		text=new JTextField(20);
		text.addActionListener(this);
		
		confirm=new JButton("OK");
		confirm.addActionListener(this);
		
		c.add(text);
		c.add(confirm);
		
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setSize(300,100);
		setLocation(240,200);
		show();
		
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if (e.getSource()==text||e.getSource()==confirm)
		{
			String s=text.getText();
			Communication.setName(s);
			//Communication.setGameFace(face);
		    //Communication.init();
		    Communication.sendName();
			//this.setVisible(false);
			this.dispose();
		}
	} 

}

⌨️ 快捷键说明

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