creceiveidmef.java
来自「windows系统下用java开发的网络入侵检测程序」· Java 代码 · 共 238 行
JAVA
238 行
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
/**
* When one peer want to send a XML IDMEF file to this JIDX Client, this window will
* be opened.<p>
* 2005.9.21
* @version 0.1.2
* @author Daxin Tian
*
*/
public class CreceiveIDMEF extends Frame implements ActionListener
{
/**
* Label "Have received ".
*/
JLabel la1;
/**
* Label "Bytes".
*/
JLabel la2;
/**
* Label "Receiving record:".
*/
JLabel la3;
/**
* Show some information of the file and the result of receiving.
*/
public TextArea ta_msg;
/**
* Show receiving progress.
*/
//public TextField tf_size;
public JProgressBar p_bar;
/**
* Button Accept. When clicked accept to receive the file.
*/
public JButton b_yes;
/**
* Button Reject. When clicked reject to receive the file.
*/
public JButton b_no;
/**
* Button Stop. When clicked intermited to receive the file.
*/
public JButton b_cancel;
/**
* Button Cancel. When clicked if not accept then send reject message and close this
* window, if have accept and is receiving then send intermited message and close this
* window, if have received over then close this window.
*/
public JButton b_cancel2;
/**
* Show receiving state.
* <ul>
* <li>0: not receiving from begin
* <li>1: receiving
* <li>2: received over
* <ul>3: not receiving because the send stop to send.
*/
public int receiving_i=0;
/**
* Point to CserverThread which is initialized when one peer connect this JIDX Client.
*/
CserverThread c_cst;
/**
*
* @param cst CserverThread which is initialized when one peer connect this JIDX Client.
*/
CreceiveIDMEF(CserverThread cst)
{
super("JIDX_Receive IDMEF File");
c_cst=cst;
setBounds(200,100,400,400);
setLayout(new BorderLayout());
setVisible(false);
la1=new JLabel("Have received ");
la3=new JLabel("Bytes");
la2=new JLabel("Receiving record:");
ta_msg=new TextArea(10,50);
ta_msg.setEditable(false);
//tf_size=new TextField(8);
//tf_size.setEditable(false);
p_bar=new JProgressBar(0,100);
p_bar.setBackground(Color.white);
p_bar.setStringPainted(true);
b_yes=new JButton("Accept");
b_no=new JButton("Reject");
b_cancel=new JButton("Stop");
b_cancel.setEnabled(false);
b_cancel2=new JButton("Cancel");
JPanel pp=new JPanel();
pp.setLayout(new BorderLayout());
JLabel l1=new JLabel("Sending record",JLabel.LEFT);
pp.add(l1,"North");
pp.add(ta_msg,"Center");
JPanel p2=new JPanel();
p2.add(la1);
//p2.add(tf_size);
p2.add(p_bar);
//JLabel la2=new JLabel("Bytes",JLabel.LEFT);
//p2.add(la2);
p2.setBackground(Color.lightGray);
Panel p1=new Panel();
p1.add(b_yes);
p1.add(b_no);
p1.add(b_cancel);
p1.add(b_cancel2);
JPanel p=new JPanel();
p.setLayout(new GridLayout(2,1));
p.add(p2);
p.add(p1);
add(pp,"Center");
add(p,"South");
pack();
b_yes.addActionListener(this);
b_no.addActionListener(this);
b_cancel.addActionListener(this);
b_cancel2.addActionListener(this);
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{setVisible(false);}
});
}
/**
* Listen button Accept, Stop, Reject,Cancel's action.
*/
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b_yes)
{
StringBuffer c_sb1=new StringBuffer();
c_sb1.append("<msg><ack_file><num>"+c_cst.fileport_num+"</num></ack_file></msg>");
//System.out.println(c_sb.toString());
try
{
c_cst.cs_dos.writeUTF(c_sb1.toString());
b_yes.setEnabled(false);
b_no.setEnabled(false);
b_cancel.setEnabled(true);
}
catch(IOException ee)
{
//System.out.println(ee);
}
}
if(e.getSource()==b_no)
{
StringBuffer c_sb2=new StringBuffer();
c_cst.fileport_b=false;
c_sb2.append("<msg><ack_file><num>"+ -1 +"</num></ack_file></msg>");
//System.out.println(c_sb.toString());
try
{
c_cst.cs_dos.writeUTF(c_sb2.toString());
setVisible(false);
}
catch(IOException ee)
{
//System.out.println(ee);
}
}
if(e.getSource()==b_cancel)
{
c_cst.fileport_b=false;
StringBuffer c_sb3=new StringBuffer();
c_sb3.append("<msg><ack_file><num>"+ -2 +"</num></ack_file></msg>");
//System.out.println(c_sb.toString());
try
{
c_cst.cs_dos.writeUTF(c_sb3.toString());
setVisible(false);
}
catch(IOException ee)
{
}
}
if(e.getSource()==b_cancel2)
{
StringBuffer c_sb=new StringBuffer();
switch(receiving_i)
{
case 0:
c_cst.fileport_b=false;
c_sb.append("<msg><ack_file><num>"+ -1 +"</num></ack_file></msg>");
try
{
c_cst.cs_dos.writeUTF(c_sb.toString());
setVisible(false);
}
catch(IOException ee)
{
//System.out.println(ee);
}
break;
case 1:
c_cst.fileport_b=false;
c_sb.append("<msg><ack_file><num>"+ -2 +"</num></ack_file></msg>");
try
{
c_cst.cs_dos.writeUTF(c_sb.toString());
setVisible(false);
}
catch(IOException ee)
{
//System.out.println(ee);
}
break;
case 2:
setVisible(false);
break;
case 3:
setVisible(false);
break;
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?