private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
int result;
JFileChooser fileChooser = new JFileChooser(); // 文件选择框
File file = null; // 接收文件
result = fileChooser.showSaveDialog(jButton2); // 显示保存框
if (result == JFileChooser.APPROVE_OPTION) { // 选择的是确定按钮
file = fileChooser.getSelectedFile(); // 得到选择的文件
JOptionPane.showMessageDialog(null, "选择的存储文件名称为:" + file.getName(), "保存", JOptionPane.ERROR_MESSAGE);
} else if (result == JFileChooser.CANCEL_OPTION) {
JOptionPane.showMessageDialog(null, "没有选择任何文件", "保存", JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "操作出现错误", "Error", JOptionPane.ERROR_MESSAGE);
}
if (file != null) {
try {
PrintStream out = new PrintStream(new FileOutputStream(file));
out.print(jPanel1.getvector());
out.close();
} catch (Exception e1) {
}
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
JFileChooser fc = new JFileChooser();
int intRetVal = fc.showOpenDialog(jButton1);
if (intRetVal == JFileChooser.APPROVE_OPTION) {
br = new BufferedReader(new FileReader(fc.getSelectedFile().getPath()));
String temp = br.readLine();
String s1=new String();
// jTextArea_Before.setText(null);
while (temp != null) {
// jTextArea_Before.append(temp + " ");
s1 += temp;
temp = br.readLine();
}
// JOptionPane.showMessageDialog(null, s1, "Error", JOptionPane.ERROR_MESSAGE);
jPanel1.setvector(s1);
jPanel1.repaint();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "文件打开失败!!!\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}