establishdialog.java

来自「完成黑白棋的开发」· Java 代码 · 共 61 行

JAVA
61
字号
package BlackAndWhite;
import BlackAndWhite.*;

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

class establishDialog extends JDialog implements ActionListener
{
	private JPanel textP1,buttonP,noticeP;
	private JLabel nameL,noticeL;
	private JTextField nameT;
	private JButton yesB,noB;
	public String name;
	public boolean yes=false;

	public establishDialog(Frame owner)
	{
		super(owner,"连接游戏",true);    
		
		nameL=new JLabel(" 本 机 名");
		nameT=new JTextField("server",20);
		textP1=new JPanel();
		textP1.add(nameL);
		textP1.add(nameT);
		
		yesB=new JButton("确定");
		noB=new JButton("取消");
		buttonP=new JPanel();
		buttonP.add(yesB);
		buttonP.add(noB);
		yesB.addActionListener(this);
		noB.addActionListener(this);
		
		noticeL=new JLabel("主机信息");
		noticeP=new JPanel();
		noticeP.add(noticeL);
		
		getContentPane().setLayout(new GridLayout(3,1));    
		getContentPane().add(noticeP);
		getContentPane().add(textP1);                        
		getContentPane().add(buttonP);
		Point p;
		p=owner.getLocation();
		int x=(int)p.getX()+200;
		int y=(int)p.getY()+150;
		this.setLocation(x,y);
		this.setLocation(x,y);
		setResizable(false);
		pack();                                      
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==yesB){
			name=nameT.getText();
			yes=true;
		}
		hide();                            
	}
}

⌨️ 快捷键说明

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