中国地质大学北京信息管理与信息系统——Java程序设计第三次上机part0在界面排序数组并输出,滚动面板改进(第二次上机实验,part1)

2021/12/20 14:49:30

本文主要是介绍中国地质大学北京信息管理与信息系统——Java程序设计第三次上机part0在界面排序数组并输出,滚动面板改进(第二次上机实验,part1),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

package Nobody_care;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

public class homework_1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
				JFrame jf=new JFrame("滚动模版测试窗口");
				jf.setLayout(new GridLayout(4,1));
				JTextArea jt1=new JTextArea(300,100);  // 写入面板
				JScrollPane js=new JScrollPane(jt1);
				JButton jb1=new JButton("写入");
				JButton jb2=new JButton("读出");
				JButton jb3=new JButton("重置");
				jb1.addActionListener(new AbstractAction() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						// TODO Auto-generated method stub
						try {
							File file=new File("C:\\Users\\Dav\\Desktop\\java_text88.txt");
							if(!file.exists()) {
								file.createNewFile();
							}
							///Users/morty/eclipse-workspace/Nobody care
							FileWriter fileWriter=new FileWriter("C:\\Users\\Dav\\Desktop\\java_text88.txt",true);
							fileWriter.write(jt1.getText());
							fileWriter.close();
						}catch(IOException e1){
							e1.printStackTrace();
						}
						jt1.setText("");
						new one();
					}
				});
				jb2.addActionListener(new AbstractAction() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						jt1.setText("");
						try {
							String sb = new String("");
							FileReader reader = new FileReader("C:\\Users\\Dav\\Desktop\\java_text88.txt");
							BufferedReader br = new BufferedReader(reader);
				 
							String str = null;
				 
							while ((str = br.readLine()) != null)
							{
								sb=sb+(str + "\n");
				 
								System.out.println(str);
							}
							jt1.setText(sb);
				 
							br.close();
							reader.close();
							
						}catch (Exception e2) {
							// TODO: handle exception
							e2.printStackTrace();
						}
						new myjd2();
					}
				});
				jb3.addActionListener(new AbstractAction() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						jt1.setText("");
					}
				});
				jf.add(js);jf.add(jb1);jf.add(jb2);jf.add(jb3);
				jf.setBounds(500,250,400,400);
				jf.setVisible(true);
				jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	}

}
class one extends JDialog{
	public one() {
		this.setVisible(true);this.setBounds(500,250,200,80);Container c = this.getContentPane();
		JLabel l1= new JLabel("写入成功",JLabel.CENTER);
		c.add(l1);
	}
}
class myjd2 extends JDialog{
	public myjd2() {
		this.setVisible(true);this.setBounds(500,250,200,80);Container c = this.getContentPane();
		JLabel l1= new JLabel("成功读入",JLabel.CENTER);
		c.add(l1);
	}
}


这篇关于中国地质大学北京信息管理与信息系统——Java程序设计第三次上机part0在界面排序数组并输出,滚动面板改进(第二次上机实验,part1)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程