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

📄 printpanel.java

📁 专家系统
💻 JAVA
字号:
package com.dbhunter.ga;

import java.awt.*;
import java.io.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
/**
 *author dbhunter
 *Email dbhunter@126.com
 */
public class PrintPanel extends JPanel implements ActionListener{
	private static final long serialVersionUID = 1L;
	private static final int MAXTEXTAREAROWS = 22,MAXTEXTAREACOLUMNS =68,MAXHEIGHT = 600,MAXWIDTH = 800;
	private JTextArea textarea;
	private JButton clearButton,saveButton, exeButton;
	private JRadioButtonMenuItem rbmisimpal,rbmidetail;
	private JScrollPane scrollPane;
	public PrintPanel(){
		this.setSize(MAXWIDTH, MAXHEIGHT);
		JPanel upPanel = new JPanel();
		JPanel downPanel = new JPanel();
		JPanel centerPanel = new JPanel();
		upPanel.setLayout(new GridLayout(1,3));
		this.textarea = new JTextArea(MAXTEXTAREAROWS,MAXTEXTAREACOLUMNS);
		this.textarea.setLineWrap (false);//设置为禁止自动换行,初始值为false.
		this.textarea.setForeground (Color.black);//字体颜色
		scrollPane = new JScrollPane(this.textarea);
		this.clearButton = new JButton("清空");
		this.saveButton = new JButton("保存");
		this.exeButton = new JButton("计算");
		ButtonGroup typeshow = new ButtonGroup();
		this.rbmisimpal = new JRadioButtonMenuItem("简单显示");
		this.rbmisimpal.setSelected(true);
		this.rbmidetail = new JRadioButtonMenuItem("详细显示");
		typeshow.add(rbmisimpal);
		typeshow.add(rbmidetail);
		this.clearButton.addActionListener(this);
		this.saveButton.addActionListener(this);
		this.exeButton.addActionListener(this);
		upPanel.add(this.rbmisimpal);
		upPanel.add(this.rbmidetail);
		upPanel.add(this.exeButton);
		centerPanel.add(this.scrollPane);
		downPanel.add(this.saveButton);
		downPanel.add(this.clearButton);
		this.add(upPanel);
		this.add(centerPanel);
		this.add(downPanel);
	}
	public void append(String str){
		this.textarea.append(str);
	}
	public void clear(){
		this.textarea.setText(" ");
	}
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==this.saveButton){
			try{
				Calendar  currentDate =Calendar.getInstance();
				String strName =""+currentDate.get(Calendar.YEAR)+(currentDate.get(Calendar.MONTH)+1)+currentDate.get(Calendar.DAY_OF_MONTH)+currentDate.get(Calendar.HOUR_OF_DAY)+currentDate.get(Calendar.MINUTE)+currentDate.get(Calendar.SECOND);
				FileOutputStream fos=new FileOutputStream(new File("document/"+strName+".txt")); 
				OutputStreamWriter osw=new OutputStreamWriter(fos); 
				String saveString=textarea.getText().replaceAll("\n","\r\n"); 
				saveString= saveString+"dbhunter create at "+currentDate.get(Calendar.YEAR)+"-"+(currentDate.get(Calendar.MONTH)+1)+"-"+currentDate.get(Calendar.DAY_OF_MONTH);
				osw.write(saveString); 
				osw.flush(); 
				osw.close(); 
				JOptionPane.showMessageDialog(null,"保存成功.保存在 document/"+strName+".txt");
			}
			catch(Exception ee) 
			{ 
			ee.printStackTrace(); 
			} 
		}
		else if(e.getSource()==this.clearButton){
			this.textarea.setText("");
		}
	}
	public JRadioButtonMenuItem getRbmidetail() {
		return rbmidetail;
	}
	public void setRbmidetail(JRadioButtonMenuItem rbmidetail) {
		this.rbmidetail = rbmidetail;
	}
	public JRadioButtonMenuItem getRbmisimpal() {
		return rbmisimpal;
	}
	public void setRbmisimpal(JRadioButtonMenuItem rbmisimpal) {
		this.rbmisimpal = rbmisimpal;
	}
	public JButton getExeButton() {
		return exeButton;
	}
	public void setExeButton(JButton exeButton) {
		this.exeButton = exeButton;
	}
}

⌨️ 快捷键说明

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