📄 cparseframe.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import org.xml.sax.*;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.swing.*;
/**
* Show parse reuslt of one XML IDMEF file. The parse task is performed by CparseIDMEF.<p>
* 2005.9.10
* @version 0.1.2
* @author Yuan Wang
*
*/
public class CparseFrame extends Frame implements ActionListener
{
/**
* Show parse result.
*/
TextArea text;
/**
*
* Show the opened XML IDMEF file's path and name.
*/
JTextField text1;
/**
* Button OK. When clicked perform the parse task.
*/
JButton button;
/**
* Button Cancel. When clicked close this window.
*/
JButton button1;
/**
* Button Open. When clicked Pop-up Open file dialog.
*/
JButton button2;
/**
* Button Clear. When clicked clear TextField text1.
*/
JButton button3;
/**
* Label "Path of the file:".
*/
JLabel label;
/**
* Open file dialog.
*/
FileDialog filedialog_load;
CparseFrame()
{
super("JIDX_Parse IDMEF");
filedialog_load=new FileDialog(this,"Open XML IDMEF",FileDialog.LOAD);
filedialog_load.setVisible(false);
setBounds(100,10,450,450);
text=new TextArea(25,30);
setVisible(false);
setLayout(new BorderLayout());
button=new JButton(" OK ");
button1=new JButton("Cancel");
button2=new JButton("Open");
button3=new JButton("Clear");
label=new JLabel("Path of the file:");
text1=new JTextField(40);
text1.setEditable(false);
JPanel p1=new JPanel();
p1.add(label);
p1.add(text1);
p1.add(button2);
p1.add(button3);
JPanel p2=new JPanel();
p2.setBackground(Color.lightGray);
p2.add(button);
p2.add(button1);
JPanel p=new JPanel();
p.setLayout(new GridLayout(2,1));
p.add(p1);
p.add(p2);
add(p,"North");
add(text,"Center");
button.addActionListener(this);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
pack();
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{setVisible(false);
}
});
filedialog_load.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{
filedialog_load.setVisible(false);}
});
}
/**
* Listen button OK,Cancel,Open,Clear's action.
*/
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button)
{
String s;
String s1;
if(text1.getText().equals(""))
{
filedialog_load.setVisible(true);
if(filedialog_load.getDirectory()==null || filedialog_load.getFile()==null)
{
text1.setText("");
}
else
{
text1.setText(filedialog_load.getDirectory()+filedialog_load.getFile());
}
}
else
{
text.setText("");
s=filedialog_load.getFile();
s1=filedialog_load.getDirectory();
SAXParserFactory factory=SAXParserFactory.newInstance();
try
{
SAXParser saxParser=factory.newSAXParser();
saxParser.parse(new File(s1,s),new CparseIDMEF(this));
}
catch(Throwable t)
{
t.printStackTrace();
}
}
}
if(e.getSource()==button1)
{
setVisible(false);
}
if(e.getSource()==button2)
{
filedialog_load.setVisible(true);
if(filedialog_load.getDirectory()==null || filedialog_load.getFile()==null)
{
text1.setText("");
}
else
{
text1.setText(filedialog_load.getDirectory()+filedialog_load.getFile());
}
}
if(e.getSource()==button3)
{
text1.setText("");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -