栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java第五次作业

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java第五次作业

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;

import javax.swing.*;

public class Ftest extends Jframe {
	private static final long serialVersionUID=1L;
	private JPanel jContentPane=null;
	private Jtextarea jtextarea=null;
	private JPanel controlPanel=null;
	private JButton openButton=null;
	private JButton closeButton =null;
	
	private JButton getOpenButton(){
		if(openButton==null){
			openButton=new JButton();
			openButton.addActionListener(new ActionListener(){
				public void actionPerformed (ActionEvent e){
					File file =new File("word.txt");
					try{
						FileWriter out =new FileWriter(file);
						String s=jtextarea.getText();
						out.write(s);
						out.close();
					}catch (Exception e1){
						e1.printStackTrace();
					}
				}
				
			});
			
		}
		return openButton;
		
	}

	private JButton getCloseButton(){
		if(closeButton==null){
			closeButton=new JButton();
			closeButton.setText("读取文件");
			closeButton.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){
					File file =new File("word.txt");
					try{
						FileReader in =new FileReader(file);
						char byt[]=new char[1024];
						int len =in.read(byt);
						jtextarea.setText(new String(byt,0,len));
						in.close();
					}catch(Exception e1){
						e1.printStackTrace();
					}
				}
			});
		}
		return closeButton;
	}
	public Ftest(){
		super();
		initialize();
	}
	private void initialize(){
		this.setSize(300,200);
		this.setContentPane(getContentPane());
		this.setTitle("Jframe");
	}
	private JPanel getJContentPane(){
		if(jContentPane==null){
			jContentPane=new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJtextarea(),BorderLayout.CENTER);
			jContentPane.add(getControlPanel(),BorderLayout.SOUTH);
		}
		return jContentPane;
	}

	private Component getControlPanel() {
		// TODO 自动生成的方法存根
		return null;
	}

	private Component getJtextarea() {
		// TODO 自动生成的方法存根
		return null;
	}

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		Ftest thisClass=new Ftest();
		thisClass.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
		thisClass.setVisible(true);
	}

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/644997.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号