csignature.java

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

JAVA
168
字号
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
/**
 * JIDX Client can use this class to look for or modify his/her signature.
 * <p>2005.9.1
 * @version 0.1.2
 * @author Administrator
 *
 */
class Csignature extends Frame implements ActionListener{


	/**
	 * Show signature.
	 */
	TextArea ta_sig=new TextArea(5,30);
	/**
	 * Button Modify. When clicked user can input a new signature.
	 */
	JButton b_m=new JButton("Modify");
	/**
	 * Button Save. When clicked user can save the new signature.
	 */
	JButton b_o=new JButton(" Save ");
	/**
	 * Button Cancel. When clicked close this window.
	 */
	JButton b_c=new JButton("Cancel");
	
	/**
	 * Point to CmainFrame's c_dis.
	 */
	DataInputStream c_dis=null;
	/**
	 * Point to CmainFrame's c_dos.
	 */
	DataOutputStream c_dos=null;
	/**
	 * The user's username.
	 */
	String c_name=null;
	
	/**
	 * 
	 * @param dis CmainFrame's c_dis.
	 * @param dos CmainFrame's c_dos.
	 * @param name The user's username.
	 */
	Csignature(DataInputStream dis,DataOutputStream dos, String name)
	{
		super("JIDX Client Signature");
	
		c_dis=dis;
		c_dos=dos;
		c_name=name;
		setBounds(200,100,200,200);
		setLayout(new GridLayout(3,1));
		JPanel p1=new JPanel();
		p1.setLayout(new GridLayout(3,1));
		JLabel l1=new JLabel();
		JLabel l2=new JLabel("Please enter the Modify button to chang your signature",JLabel.CENTER);
		
		JLabel l3=new JLabel();
		p1.add(l1);
		p1.add(l2);
		p1.add(l3);
		
		JPanel p2=new JPanel();
		p2.setLayout(new GridLayout(3,1));
		JLabel l4=new JLabel();
		JLabel l5=new JLabel();
		JPanel p=new JPanel();
		p.add(b_m);
		p.add(b_o);
		p.add(b_c);
		p.setBackground(Color.lightGray);
		p2.add(l4);
		p2.add(p);
		p2.add(l5);
		ta_sig.setEditable(false);
		add(p1);
		add(ta_sig);
		add(p2);
		
		
		pack();
		b_m.addActionListener(this);
		b_o.addActionListener(this);
		b_c.addActionListener(this);
		setVisible(false);
		addWindowListener(new WindowAdapter()
				  {public void windowClosing(WindowEvent e)
				  	{setVisible(false);}
				  }
				);
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==b_o)
		{
			
			
			String c_sig=null;
			StringBuffer c_sb=new StringBuffer();
			c_sig=ta_sig.getText();
			
			c_sb.append("<msg><mod_signature><name>"+c_name+"</name><sig>"+c_sig+"</sig></mod_signature></msg>");
			
			
			try
			{
				//System.out.println("send mod: "+c_sb.toString());
				c_dos.writeUTF(c_sb.toString());
				
				
				
			}
			catch(IOException ee)
			{
				
			}
			c_send();
		
		}
		if(e.getSource()==b_m)
		{
			ta_sig.setEditable(true);
			b_o.setEnabled(true);
		
		}
		if(e.getSource()==b_c)
		{
			setVisible(false);
		}
	}
	
	/**
	 * Ask JIDX Server the user's signature. 
	 *
	 */
	
	public void c_send()
	{
		StringBuffer c_sb2=new StringBuffer();
		
		c_sb2.append("<msg><req_signature><name>"+c_name+"</name></req_signature></msg>");
	
		try
		{
			//System.out.println("send req: "+c_sb2.toString());
			
			c_dos.writeUTF(c_sb2.toString());
			b_o.setEnabled(false);
			ta_sig.setEditable(false);
			ta_sig.setText(null);
			
			
		}
		catch(IOException ee)
		{
			System.out.println(ee);
		}
	}
}

⌨️ 快捷键说明

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