标签:tde while pack exce package and amp log print
package Java0;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;
public class NotepadTest extends JFrame implements ActionListener {
JFrame frame;
JTextArea jTextArea = null;
JMenuBar jMenuBar =null;
JMenu jMenu=null;
JMenuItem jMenuItem1 =null;
JMenuItem jMenuItem2 =null;
JFileChooser jFileChooser=null;
FileReader fileReader =null;
FileWriter fileWriter= null;
BufferedReader bufferedReader=null;
BufferedWriter bufferedWriter=null;
public NotepadTest() {
JFrame frame = new JFrame("记事本");
jTextArea =new JTextArea();
jMenuBar=new JMenuBar ();
jMenu=new JMenu ("文件");
jMenuItem1=new JMenuItem("打开");
jMenuItem2=new JMenuItem("保存");
jFileChooser=new JFileChooser();
jTextArea.setBackground(Color.white );
frame.setJMenuBar(jMenuBar);
jMenuBar.add(jMenu);
jMenu.add(jMenuItem1);
jMenu.add(jMenuItem2);
frame.add(jTextArea);
frame.setTitle("罗宇梁记事本");
frame.setSize(800,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
NotepadTest notepadTest=new NotepadTest();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getActionCommand().equals("打开"));{
jFileChooser = new JFileChooser();
jFileChooser.setDialogTitle("你在干什么");
jFileChooser.showOpenDialog(null);
jFileChooser.setVisible(true);
String address=jFileChooser.getSelectedFile().getAbsolutePath();
try {
fileReader =new FileReader(address);
bufferedReader = new BufferedReader(fileReader);
String str = "";
String strAll = "";
while((str = bufferedReader.readLine())!=null) {
strAll +=str +"\r\n";
}
jTextArea.setText(strAll);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}finally {
try {
bufferedReader.close();
fileReader.close ();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
}
标签:tde while pack exce package and amp log print
原文地址:https://www.cnblogs.com/luoyuliang/p/11953422.html