能不能帮忙看看记事本
package 记事本;import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import
import
import
import
import
import
import
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.filechooser.FileNameExtensionFilter;
public class MyNoteBook extends JFrame implements ActionListener {
static final int i=0;
static final String LINE_SEPARATOR =System.getProperty("Line_separator");
JFrame jf,jf1,jf3;
JScrollPane jsc;
JMenu menu;
JMenuBar menubar;
JMenuItem item1,item2,item3,item4;
JTextArea jtext,jtext1,jtext2;
JFileChooser chooser;
JDialog dialog;
JButton jb1,jb2;
JPanel jp;
public MyNoteBook() {
Inint();
}
private void Inint() {
jf=new JFrame("我的记事本");
menu=new JMenu("文件");
menubar=new JMenuBar();
jf.setJMenuBar(menubar);
menubar.add(menu);
jtext=new JTextArea();
jsc=new JScrollPane(jtext);
jf.add(jsc);
item1=new JMenuItem("打开");
item2=new JMenuItem("保存");
item4=new JMenuItem("另存为");
item3=new JMenuItem("退出");
menu.add(item1);
menu.addSeparator();
menu.add(item2);
menu.addSeparator();
menu.add(item4);
menu.addSeparator();
menu.add(item3);
item1.addActionListener(this);
item2.addActionListener(this);
item3.addActionListener(this);
jf.setVisible(true);
jf.setBounds(300, 100, 500, 500);
}
public void actionPerformed(ActionEvent e) {
BufferedReader buf = null;
FileReader fr=null;
if(e.getSource()==item1)//打开文件
{
try
{
JFileChooser chooser = new JFileChooser();
int c=chooser.showOpenDialog(this);
if(c==JFileChooser.CANCEL_OPTION)
return;
else
{
File file=chooser.getSelectedFile();
fr = new FileReader(file);
buf=new BufferedReader(fr);
String line=null;
jtext.setText("");
while((line=buf.readLine())!=null)
jtext.append(line+"\r\n");
}
} catch (FileNotFoundException e1) {
} catch (IOException e1) {
}
finally
{
if(buf!=null)
try {
buf.close();
} catch (IOException e1) {
}
}
}
if(e.getSource()==item2)//保存文件
{
try
{
File f =new File("新建文本文件.txt");
if(f.exists()==true)
{
Show();
}
else
{
Method();
}
} catch (IOException e1) {
}
}
if(e.getSource()==item3)//另存为文件
{
FileWriter fw=null;
BufferedWriter buw=null;
try
{
JFileChooser chooser = new JFileChooser();
chooser.showSaveDialog(this);
String S=chooser.getSelectedFile().getAbsolutePath();
fw=new FileWriter(S);
buw=new BufferedWriter(fw);
String s=jtext.getText();
buw.write(s);
buw.flush();
} catch (IOException e1) {
}
finally{
if(buw!=null)
try {
buw.close();
} catch (IOException e1) {
}
}
}
}
private void Method() throws IOException {
FileWriter fw=new FileWriter("新建文本文件.txt");
BufferedWriter buw=new BufferedWriter(fw);
String s=jtext.getText();
buw.write(s);
buw.flush();
buw.close();
}
void Show() {
jf1=new JFrame("警告");
jb1=new JButton("确定");
jb2=new JButton("取消");
jp=new JPanel();
jp.add(jb1);
jp.add(jb2);
jtext1=new JTextArea("有同名文件,是否覆盖!!");
jtext1.setEditable(false);
jf1.setLayout(new BorderLayout());
jf1.add("Center",jtext1);
jf1.add("South",jp);
jf1.setVisible(true);
jf1.setBounds(400,200,300,200);
jb1.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e) {
try
{
Method() ;
} catch (IOException e1) {
}
}
});
jb2.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e) {
jf3=new JFrame("提示");
jtext2=new JTextArea("请把文件另存为!");
jtext2.setEditable(false);
jf3.add(jtext2);
jf3.setVisible(true);
jf3.setBounds(400,400, 300, 100);
}
});
}
public static void main(String[] args) {
new MyNoteBook();
}
}
请问下在另存为的地方怎么弄啊!!!!我弄的就是显示不出来!!