⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logrightpanel.java

📁 模仿腾讯QQ的
💻 JAVA
字号:
package com.softfz.jn0708.main.log;



import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.TitledBorder;

import com.softfz.jn0708.util.Log;

/**
 * 日志面板中的右面板.
 * 
 * @author 
 * 
 */
public class LogRightPanel extends JPanel {

	private static final long serialVersionUID = -5151668720717559856L;

	private Log serLog = null;

	private JComboBox yearCB = null;

	private JComboBox monthCB = null;

	private JComboBox dayCB = null;

	private JButton searchBtn = null;

	private JTextArea historyTextArea = null;

	/**
	 * 构造方法.
	 * 
	 */
	public LogRightPanel() {
		this.serLog = Log.getInstance(LogRightPanel.class);
		init();
	}

	/**
	 * 面板初始化方法
	 *
	 */
	private void init() {

		this.setLayout(new BorderLayout());
		this.add(getUpPanel(), BorderLayout.NORTH);
		this.add(getHistoryLogPanel(), BorderLayout.CENTER);
		this.setBackground(new Color(241,250,255));
		searchLog(getDate());
	}

	/**
	 * 获取历史日志的方法
	 * @return
	 */
	private Component getHistoryLogPanel() {

		historyTextArea = new JTextArea();
		historyTextArea.setEditable(false);
		JScrollPane scrollPane = new JScrollPane(historyTextArea);
		JPanel historyLogPanel = new JPanel();
		historyLogPanel.setBackground(new Color(241,250,255));
		historyLogPanel.setLayout(new BorderLayout());
		historyLogPanel.add(scrollPane);
		historyLogPanel.setBorder(new TitledBorder("历史日志查询"));
		
		return historyLogPanel;
	}

	/**
	 * 后驱查询面板
	 * @return
	 */
	private Component getUpPanel() {

		Vector yearVector = new Vector();
		yearVector.add("");
		for (int i = 1990; i <= 2010; i++) {
			yearVector.add(String.valueOf(i));
		}
		yearCB = new JComboBox(yearVector);
		JLabel yearLab = new JLabel("年");

		Vector monthVector = new Vector();
		monthVector.add("");
		for (int i = 1; i <= 12; i++) {
			monthVector.add(String.valueOf(i));
		}
		monthCB = new JComboBox(monthVector);
		JLabel monthLab = new JLabel("月");

		Vector dayVector = new Vector();
		dayVector.add("");
		for (int i = 1; i <= 31; i++) {
			dayVector.add(String.valueOf(i));
		}
		dayCB = new JComboBox(dayVector);
		JLabel dayLab = new JLabel("日");

		searchBtn = new JButton("查询");
		searchBtn.addActionListener(new LogRightListener());

		Box searchBox = Box.createHorizontalBox();
		searchBox.add(yearCB);
		searchBox.add(yearLab);
		searchBox.add(monthCB);
		searchBox.add(monthLab);
		searchBox.add(dayCB);
		searchBox.add(dayLab);
		searchBox.add(searchBtn);
		searchBox.setBackground(new Color(241,250,255));

		JPanel searchPanel = new JPanel();
		searchPanel.setBackground(new Color(241,250,255));
		searchPanel.setLayout(new BorderLayout());
		searchPanel.add(searchBox);
		searchPanel.setBorder(new TitledBorder("选择日期"));


		return searchPanel;
	}

	/**
	 * 获取日期的方法
	 * @return
	 */
	private String getDate(){
		String tempstr = "";
		String returnStr = "";
		returnStr = returnStr + (String)yearCB.getSelectedItem();
		returnStr = returnStr + "-";
		
		tempstr = (String)monthCB.getSelectedItem();
		if (tempstr.length()==1){
			tempstr = "0"+tempstr;
		}
		returnStr = returnStr + tempstr;
		returnStr = returnStr + "-";
		
		tempstr = (String)dayCB.getSelectedItem();
		if (tempstr.length()==1){
			tempstr = "0"+tempstr;
		}
		returnStr = returnStr + tempstr;
		
		if (returnStr.equals("--")){
			returnStr = "";
		}
		return returnStr;
		
	}
	
	/**
	 * 查询日志 方法
	 * @param dateStr
	 */
	private void searchLog(String dateStr) {
		
		historyTextArea.setText("");
		
		FileReader fReader = null;
		BufferedReader bReader = null;
		String tempStr = null;
		try {
			fReader = new FileReader("./Log.txt");
			bReader = new BufferedReader(fReader);
			while ((tempStr = bReader.readLine()) != null) {
				if (tempStr.indexOf(dateStr) != -1){
					historyTextArea.append(tempStr);
					historyTextArea.append("\n");
					
				}
			}
		} catch (FileNotFoundException e) {
			serLog.log(e);
		} catch (IOException e) {
			serLog.log(e);
		}
	}

	/**
	 * 查询按钮监听
	 * @author admin
	 *
	 */
	class LogRightListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {

			searchLog(getDate());
		}

	}

	/**
	 * 获取历史日志文本域
	 * @return
	 */
	public JTextArea getHistoryTextArea() {
		return historyTextArea;
	}

}

⌨️ 快捷键说明

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