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

📄 readlog.java

📁 图书管理系统v1.0是使用JAVA语言开发的解决图书基本管理的一个应用程序。 该系统能够实现简单的图书和用户管理
💻 JAVA
字号:
package lib;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;

public class ReadLog extends JInternalFrame {
	/***************************************************************************
	 ***      declaration of the private variables used in the program       ***
	 ***************************************************************************/

	//for creating the North Panel
	private JPanel northPanel = new JPanel();
	//for creating the Center Panel
	private JPanel centerPanel = new JPanel();
	//for creating the label
	private JLabel northLabel = new JLabel("日志文件");
	//for creating the button
	private JButton clearButton;
	//for creating the table
	private JTextArea ta;
	//for creating the TableColumn
	//for creating the JScrollPane
	private JScrollPane scrollPane;
	
	public ReadLog() {
		//for setting the title for the internal frame
		super("日志",true,true,true, true );
		//for setting the icon
		setFrameIcon(new ImageIcon(ClassLoader.getSystemResource("images/List16.gif")));
		init();
	}
	private void init()
	{
	    Container cp = getContentPane();
	    ta = new JTextArea();
	    ta.setEditable(false);
		scrollPane = new JScrollPane(ta);
	    try{
	   	 String temp;
		    FileReader fr = new FileReader("database/log.txt");
		    BufferedReader bf =new BufferedReader(fr);
		    while((temp=bf.readLine())!=null){ta.append(temp);ta.append("\n");}
	   	 bf.close();
	  	  fr.close();
		}
		catch (FileNotFoundException e){
		    System.out.println("File not Found!");
		}
		catch(IOException e){}
	    //for setting the size for the table
		//for setting the scrollpane to the table
		northLabel.setFont(new Font("Default", Font.BOLD, 14));
		//for setting the layout to the panel
		northPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		//for adding the label to the panel
		northPanel.add(northLabel);
		//for adding the panel to the container
		cp.add("North", northPanel);

		//for setting the layout to the panel
		centerPanel.setLayout(new BorderLayout());
		//for creating an image for the button
	
		ImageIcon refreshIcon = new ImageIcon(ClassLoader.getSystemResource("images/refresh.gif"));
		clearButton = new JButton("清空日志文件",refreshIcon);
		clearButton.setToolTipText("清空");
		clearButton.setFont(new Font("default",Font.PLAIN, 12));
		
		//for adding the scrollpane to the panel
		centerPanel.add(scrollPane, BorderLayout.CENTER);
		
		centerPanel.add(clearButton,BorderLayout.SOUTH);
		//for setting the border to the panel
		centerPanel.setBorder(BorderFactory.createTitledBorder("文件内容:"));
		//for adding the panel to the container
		cp.add("Center", centerPanel);


		clearButton.addActionListener(new ActionListener(){
		    public void actionPerformed(ActionEvent ae){
		        centerPanel.setVisible(false);
		        centerPanel.remove(scrollPane);
		 	   ta = new JTextArea();
				scrollPane = new JScrollPane(ta);
				try{
		    	    FileWriter fw = new FileWriter("database/log.txt");
		  		  fw.write("");
					fw.flush();
					fw.close();
				}
				catch (FileNotFoundException e){
		    	System.out.println("File not Found!");
				}
				catch(IOException e){}
				centerPanel.add(scrollPane,BorderLayout.CENTER);
				centerPanel.setVisible(true);
		 	}
		});		        
		        
		//for setting the visible to true
		setVisible(true);
		//to show the frame
		pack();
	}
}

⌨️ 快捷键说明

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