import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JTextField;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import java.io.*;
import java.awt.*;
public class testmsg extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTextField jTextField = null;
private JLabel jLabel = null;
private JButton jButton1 = null;
private JScrollPane jScrollPane = null;
private JTextArea jTextArea = null;
private JButton jButton2 = null;
/**
* This is the default constructor
*/
public testmsg() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(604, 324);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(9, 19, 42, 51));
jLabel.setText(" 路径");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJTextField(), null);
jContentPane.add(jLabel, null);
jContentPane.add(getJButton1(), null);
jContentPane.add(getJScrollPane(), null);
jContentPane.add(getJButton2(), null);
}
return jContentPane;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(63, 25, 330, 45));
}
return jTextField;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(473, 20, 114, 48));
jButton1.setText("读入");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String name = jTextField.getText();
File ss = new File(name);
try {
FileReader a = new FileReader(ss);
BufferedReader br = new BufferedReader(a);
String s = br.readLine();
String t=s;
while(s!=null){
s= br.readLine();
t= t+"/n"+s;
}
t=t.substring(0,t.length()-4);
jTextArea.setText(t);
br.close();
}
catch (IOException e1) {
JOptionPane.showMessageDialog(null, "文件路径错误,请重新输入");
}
}
});
}
return jButton1;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(10, 103, 444, 174));
jScrollPane.setViewportView(getJTextArea());
}
return jScrollPane;
}
/**
* This method initializes jTextArea
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextArea() {
if (jTextArea == null) {
jTextArea = new JTextArea();
jTextArea.setText("");
}
return jTextArea;
}
/**
* This method initializes jButton2
*
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setBounds(new Rectangle(480, 215, 110, 55));
jButton2.setText("保存");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String name = jTextField.getText();
String s = null;
s=jTextArea.getText();//把所有的值都赋给了s 所以下面不用判断while了 输出直接全部输出了
File file = new File(name);
try {
PrintWriter br = new PrintWriter(new FileWriter(file));
String nam = jTextField.getText();
br.println(s);
//s=jTextArea.getText();
br.close();
} catch (IOException e2) {
JOptionPane.showMessageDialog(null, "文件路径错误,请检查路径");
}
}
});
}
return jButton2;
}
}