cserverframe.java

来自「windows系统下用java开发的网络入侵检测程序」· Java 代码 · 共 183 行

JAVA
183
字号
import java.awt.*;
import java.awt.event.*;
import java.util.LinkedList;
import javax.swing.*;
/**
 * Show who have connected myself.<p>
 * 2005.9.12
 * @version 0.1.2
 * @author Daxin Tian
 *
 */
public class CserverFrame extends Frame implements ActionListener{
	
	/**
	 * List the usernames who have connected me.
	 */
	public List l_conning=new List(5);
	/**
	 * Record the CserverThread according to connected user. If the client double click
	 * one username in the list--l_conning, then a message dialog will ask whether want to
	 * disconnect the peer, if yes is choosen, the username will be removed from l_conning and
	 * his/her according  CserverThread will be removed from l_serverThread too.
	 */
	public LinkedList l_serverThread=new LinkedList();
	/**
	 * Button Cancel.  Close this window.
	 */
	JButton b_ok=new JButton("Cancel");
	/**
	 * Label "Connecting Peers".
	 */
	
	JLabel la=new JLabel("Connecting Peers",JLabel.CENTER);
	CserverFrame()
	{
		super("JIDX Connecting Peers");
		setBounds(250,100,200,200);
		setLayout(new BorderLayout());
		
		JPanel p1=new JPanel();
		
		p1.add(l_conning);
		
		JPanel p=new JPanel();
		p.setLayout(new GridLayout(2,1));
		Label l1=new Label("You can double click the user and choose whether disconnect him/her",JLabel.CENTER);
		l1.setBackground(Color.red);
		JPanel p3=new JPanel();
		p3.setBackground(Color.lightGray);
		p3.add(b_ok);
		p.add(l1);
		p.add(p3);
		add(la,"North");
		add(p1,"Center");
		add(p,"South");
		
		setVisible(false);
		pack();
		b_ok.addActionListener(this);
		l_conning.addActionListener(this);
		addWindowListener(new WindowAdapter()
				  {public void windowClosing(WindowEvent e)
				  	{setVisible(false);}
				  }
				);
	}
	/**
	 * Listen to List l_conning and Button OK's action.
	 */
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==l_conning)
		{
			CserverFrameMsg msg=new CserverFrameMsg(this);
			msg.show("Do you confirm to disconnect the user?");
			
		}
		if(e.getSource()==b_ok)
		{
			setVisible(false);
		}
	}

}
/**
 * Prompt dialog ask user whether disconnect the connected peer.
 * <p>2005.9.13
 * @version 0.1.2
 * @author Administrator
 *
 */
class CserverFrameMsg extends Frame implements ActionListener
{
	/**
	 * Button Yes.  If Clicked the peer will be disconnected. 
	 */
	JButton b_ok;
	/**
	 * Button No.  If Clicked the peer will not be disconnected and close this window. 
	 */
	JButton b_no;
	/**
	 * Label "Prompt".
	 */
    JLabel l_msg;
    /**
     * The prompt message will be writed in it.
     */
    JTextField tt=new JTextField(31);
    /**
     * The Yes and No button's action will tell CserverFrame whether disconnect the peer.
     */
	CserverFrame c_csf;
	CserverFrameMsg(CserverFrame csf)
	{
		super("JIDX");
		c_csf=csf;
		
    	setBounds(300,300,150,100);
    	setLayout(new BorderLayout());
    	
    	b_ok=new JButton("Yes");
    	
    	b_no=new JButton("No");
    	
    	JPanel p1;
    	l_msg=new JLabel("Prompt",JLabel.CENTER);
    	l_msg.setBackground(Color.red);
    	p1=new JPanel();
    	p1.setBackground(Color.lightGray);
    	p1.add(b_ok);
    	p1.add(b_no);
    	add(l_msg,"North");
    	add(tt,"Center");
    	add(p1,"South");
    	
    	b_ok.addActionListener(this);
    	b_no.addActionListener(this);
    	setVisible(false);
    	
    	addWindowListener(new WindowAdapter()
    			  {public void windowClosing(WindowEvent e)
    			  	{setVisible(false);}
    			  }
    			);
    	pack();

		
	}
	/**
	 * 
	 * @param s The prompt message.
	 */
	public void show(String s)
    {
    	tt.setText(s);
    	
    	setVisible(true);
    }
    /**
     * Listen to button Yes and No's action.
     */
	public void actionPerformed(ActionEvent e)
    {
    	if(e.getSource()==b_ok)
    	{
    		int i=c_csf.l_conning.getSelectedIndex();
			CserverThread cst;
			cst=(CserverThread)c_csf.l_serverThread.get(i);
			
			c_csf.l_conning.remove(i);
			c_csf.l_serverThread.remove(i);
			cst.CserverThreadclose();
    		setVisible(false);
    	}
    	if(e.getSource()==b_no)
    	{
    		
    		setVisible(false);
    	}
    }
}

⌨️ 快捷键说明

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