www.pudn.com > mailserver.rar > ErrorLog.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 ErrorLog 
{ 
 
	//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; 
	} 
 
	 
	private JComboBox getJComboBox() 
	{ 
		if (jComboBox == null) 
		{ 
			jComboBox = new JComboBox(); 
			jComboBox.setLocation(new Point(145, 34)); 
			jComboBox.setSize(new Dimension(114, 20)); 
			jComboBox.addItem("error.log"); 
		} 
		return jComboBox; 
	} 
 
	/** 
	 * This method initializes jEditorPane	 
	 * 	 
	 * @return javax.swing.JEditorPane	 
	 */ 
	File errorFile; 
	FileInputStream  fileStream;  //  @jve:decl-index=0: 
	private JScrollPane jScrollPane = null;	 
	private JEditorPane jEditorPane1 = 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) 
				{ 
					jEditorPane1.setText(""); 
					if(fileStream!=null) 
					{ 
						try 
						{ 
							fileStream.close(); 
							 
						} 
						catch(IOException ex) 
						{ 
							 AdminViewExam.adminLog.println("close file: error.log is error"); 
							 
						} 
						finally 
						{ 
							// TODO Auto-generated Event stub actionPerformed() 
						 	 errorFile.delete();							 
						} 
	 
					} 
					 
				    //System.out.println(errorFile.delete()); 
				} 
			}); 
		} 
		return jButton; 
	} 
 
	/** 
	 * This method initializes jButton1	 
	 * 	 
	 * @return javax.swing.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; 
	} 
 
	 
	private JScrollPane getJScrollPane() 
	{ 
		if (jScrollPane == null) 
		{ 
			jScrollPane = new JScrollPane(); 
			jScrollPane.setViewportView(getJEditorPane1()); 
		} 
		return jScrollPane; 
	} 
 
 
	 
	 
	/** 
	 * This method initializes jEditorPane1	 
	 * 	 
	 * @return javax.swing.JEditorPane	 
	 */ 
	private JEditorPane getJEditorPane1() 
	{ 
		 
		errorFile=new File("xiaobai\\mailserver\\log\\error.log"); 
		if(!errorFile.exists()) 
		{ 
			try 
			{ 
				errorFile.createNewFile(); 
			} 
			catch(IOException e) 
			{ 
				 AdminViewExam.adminLog.println("create file: error.log is error"); 
			} 
		} 
		try 
		{ 
			fileStream=new FileInputStream(errorFile); 
			 
		} 
		catch(FileNotFoundException e) 
		{ 
			AdminViewExam.adminLog.println("file: error.log is not found"); 
		} 
		 
		if (jEditorPane1 == null) 
		{ 
			jEditorPane1 = new JEditorPane(); 
		    jEditorPane1.setEditable(false); 
			try 
			{ 
				jEditorPane1.read(fileStream,null); 
				 
			} 
			catch(IOException e) 
			{ 
				AdminViewExam.adminLog.println("read: error.log is error"); 
				 
			}	 
		 
		} 
 
		return jEditorPane1; 
	} 
	 
}