www.pudn.com > mailserver.rar > SMTPLog.java
package xiaobai.mailserver.admin;
//import javax.swing.JFrame;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class SMTPLog
{
//private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="14,-20"
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JPanel jPanel = null;
private JLabel jLabel1 = null;
private JComboBox jComboBox = null;
private JPanel jPanel1 = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JButton jButton2 = null;
/*
private JFrame getJFrame()
{
if (jFrame == null)
{
jFrame = new JFrame();
jFrame.setSize(new Dimension(462, 357));
jFrame.setContentPane(getJContentPane());
}
return jFrame;
}*/
protected JPanel getJContentPane()
{
if (jContentPane == null)
{
jLabel = new JLabel();
jLabel.setText("系统日志:");
jLabel.setSize(new Dimension(65, 20));
jLabel.setLocation(new Point(10, 12));
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.setPreferredSize(new Dimension(120, 35));
jContentPane.add(getJPanel(), BorderLayout.NORTH);
jContentPane.add(getJPanel1(), BorderLayout.SOUTH);
jContentPane.add(getJScrollPane(), BorderLayout.CENTER);
}
return jContentPane;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel()
{
if (jPanel == null)
{
jLabel1 = new JLabel();
jLabel1.setPreferredSize(new Dimension(36, 20));
jLabel1.setLocation(new Point(38, 34));
jLabel1.setSize(new Dimension(107, 20));
jLabel1.setText("日志文件名称:");
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.setPreferredSize(new Dimension(120, 60));
jPanel.add(jLabel, null);
jPanel.add(jLabel1, null);
jPanel.add(getJComboBox(), null);
}
return jPanel;
}
/**
* This method initializes jComboBox
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox()
{
if (jComboBox == null)
{
jComboBox = new JComboBox();
jComboBox.setLocation(new Point(145, 34));
jComboBox.setSize(new Dimension(114, 20));
jComboBox.addItem("smtp.log");
}
return jComboBox;
}
/**
* This method initializes jEditorPane
*
* @return javax.swing.JEditorPane
*/
File smtpFile;
FileInputStream fileStream; // @jve:decl-index=0:
private JScrollPane jScrollPane = null;
private JEditorPane jEditorPane = null;
private JPanel getJPanel1()
{
if (jPanel1 == null)
{
jPanel1 = new JPanel();
jPanel1.setLayout(null);
jPanel1.setPreferredSize(new Dimension(460, 45));
jPanel1.add(getJButton(), null);
jPanel1.add(getJButton1(), null);
jPanel1.add(getJButton2(), null);
}
return jPanel1;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton()
{
if (jButton == null)
{
jButton = new JButton();
jButton.setLocation(new Point(50, 16));
jButton.setText("清空");
jButton.setSize(new Dimension(66, 20));
jButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
jEditorPane.setText("");
if(fileStream!=null)
{
try
{
fileStream.close();
}
catch(IOException ex)
{
AdminViewExam.adminLog.println("close file: smtp.log is error");
}
finally
{
// TODO Auto-generated Event stub actionPerformed()
smtpFile.delete();
}
}
}
});
}
return jButton;
}
private JButton getJButton1()
{
if (jButton1 == null)
{
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(135, 16, 66, 20));
jButton1.setText("打开");
}
return jButton1;
}
/**
* This method initializes jButton2
*
* @return javax.swing.JButton
*/
private JButton getJButton2()
{
if (jButton2 == null)
{
jButton2 = new JButton();
jButton2.setLocation(new Point(340, 16));
jButton2.setText("刷新");
jButton2.setSize(new Dimension(66, 20));
}
return jButton2;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane()
{
if (jScrollPane == null)
{
jScrollPane = new JScrollPane();
jScrollPane.setViewportView(getJEditorPane2());
}
return jScrollPane;
}
private JEditorPane getJEditorPane2()
{
smtpFile=new File("xiaobai\\mailserver\\log\\smtp.log");
if(!smtpFile.exists())
{
try
{
smtpFile.createNewFile();
}
catch(IOException e)
{
AdminViewExam.adminLog.println("create file: smtp.log is error");
}
}
try
{
fileStream=new FileInputStream(smtpFile);
}
catch(FileNotFoundException e)
{
AdminViewExam.adminLog.println("file: smtp.log is not found");
}
if (jEditorPane == null)
{
jEditorPane = new JEditorPane();
jEditorPane.setEditable(false);
try
{
jEditorPane.read(fileStream,null);
}
catch(IOException e)
{
AdminViewExam.adminLog.println("read file: smtp.log is error");
}
}
return jEditorPane;
}
}