麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

filewriter與filereader類實例15.04

2019-11-14 10:04:18
字體:
供稿:網(wǎng)友
import java.awt.*;import java.awt.event.*;import java.io.*;import javax.swing.*;public class Ftest extends JFrame { // 創(chuàng)建類,繼承Jframe類	PRivate JScrollPane scrollPane;	private static final long serialVersionUID = 1L;	private JPanel jContentPane = null; // 創(chuàng)建面板對象	private JTextArea jTextArea = null; // 創(chuàng)建文本域?qū)ο?private JPanel controlPanel = null; // 創(chuàng)建面板對象	private JButton openButton = null; // 創(chuàng)建按鈕對象	private JButton closeButton = null; // 創(chuàng)建按鈕對象		private JTextArea getJTextArea() {		if (jTextArea == null) {			jTextArea = new JTextArea();		}		return jTextArea;	}		private JPanel getControlPanel() {		if (controlPanel == null) {			FlowLayout flowLayout = new FlowLayout();			flowLayout.setVgap(1);			controlPanel = new JPanel();			controlPanel.setLayout(flowLayout);			controlPanel.add(getOpenButton(), null);			controlPanel.add(getCloseButton(), null);		}		return controlPanel;	}		private JButton getOpenButton() {		if (openButton == null) {			openButton = new JButton();			openButton.setText("寫入文件"); // 修改按鈕的提示信息			openButton					.addActionListener(new java.awt.event.ActionListener() {						// 按鈕的單擊事件						public void actionPerformed(ActionEvent e) {							// 創(chuàng)建文件對象							File file = new File("Word.txt");							try {								// 創(chuàng)建FileWriter對象								FileWriter out = new FileWriter(file);								// 獲取文本域中文本								String s = jTextArea.getText();								out.write(s); // 將信息寫入磁盤文件								out.close(); // 將流關(guān)閉							} catch (Exception e1) {								e1.printStackTrace();							}						}					});		}		return openButton;	}		private JButton getCloseButton() {		if (closeButton == null) {			closeButton = new JButton();			closeButton.setText("讀取文件"); // 修改按鈕的提示信息			closeButton					.addActionListener(new java.awt.event.ActionListener() {						// 按鈕的單擊事件						public void actionPerformed(ActionEvent e) {							File file = new File("word.txt"); // 創(chuàng)建文件對象							try {								// 創(chuàng)建FileReader對象								FileReader in = new FileReader(file);								char byt[] = new char[1024]; // 創(chuàng)建char型數(shù)組								int len = in.read(byt); // 將字節(jié)讀入數(shù)組								// 設(shè)置文本域的顯示信息								jTextArea.setText(new String(byt, 0, len));								in.close(); // 關(guān)閉流							} catch (Exception e1) {								e1.printStackTrace();							}						}					});		}		return closeButton;	}		public Ftest() {		super();		initialize();	}		private void initialize() {		this.setSize(300, 200);		this.setContentPane(getJContentPane());		this.setTitle("JFrame");	}		private JPanel getJContentPane() {		if (jContentPane == null) {			jContentPane = new JPanel();			jContentPane.setLayout(new BorderLayout());			jContentPane.add(getScrollPane(), BorderLayout.CENTER);			jContentPane.add(getControlPanel(), BorderLayout.SOUTH);		}		return jContentPane;	}		public static void main(String[] args) { // 主方法		Ftest thisClass = new Ftest(); // 創(chuàng)建本類對象		thisClass.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE);		thisClass.setVisible(true); // 設(shè)置該窗體為顯示狀態(tài)	}	/**	 * @return	 */	protected JScrollPane getScrollPane() {		if (scrollPane == null) {			scrollPane = new JScrollPane();			scrollPane.setViewportView(getJTextArea());		}		return scrollPane;	}}
上一篇:JS多重繼承

下一篇:文件夾和文件壓縮

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 亚洲欧美日韩免费 | 又黄又爽免费无遮挡在线观看 | 久久国产精品网 | 精品国产一区二区三 | 91成人在线免费视频 | 国产精品久久久久久久四虎电影 | 国产毛片视频 | 综合网日日天干夜夜久久 | 羞羞视频在线免费 | 久久久精品99 | 亚洲精品 在线播放 | 免费黄色入口 | 日韩精品中文字幕在线观看 | 亚洲欧美在线视频免费 | 毛片在线免费观看网址 | 一级网站 | 蜜桃网在线 | 久草成人在线 | 海角在线观看91一区二区 | 四虎久草 | 国产激爽大片在线播放 | 一区二区三区黄色 | 成人在线高清视频 | 欧美亚成人 | av成人一区二区 | 成年免费观看视频 | 国产一级午夜 | 在线亚洲欧美 | 看免费黄色大片 | 精品久久久久久国产三级 | 伊人午夜视频 | 九九热在线观看视频 | 久久久电影电视剧免费看 | 久草在线最新 | 一级性色 | 色播久久 | 久久精品亚洲精品国产欧美kt∨ | 369看片你懂的小视频在线观看 | 特色一级黄色片 | 99re66热这里只有精品8 | 国产精品免费久久久 |