java错误

woaiqian520 2009-11-01 09:46:20
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.*;


public class ss extends JFrame implements ActionListener
{
File file=null;
JFileChooser filechooser=new JFileChooser();//文件选择框
JButton openButton=new JButton("打开文件");
JButton saveButton=new JButton("保存文件");
JPanel panel1=new JPanel();//放按钮的Panel
JTextPane text=new JTextPane();//这是用来存放文本的
public ss()
{
super("文本编译器");
Container cn=this.getContentPane();
cn.setLayout(new BorderLayout());
openButton.addActionListener(this);
saveButton.addActionListener(this);
panel1.add(openButton);
panel1.add(saveButton);
cn.add(panel1,BorderLayout.NORTH);
//将Text放到一个JScrollPane控件可以实现滚动条
cn.add(new JScrollPane(text),BorderLayout.CENTER);
this.setSize(400, 300);
this.show();
}
public void saveFile();
{
try {
FileWriter fw = new FileWriter(file);
fw.write(text.getText());
fw.close();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
public void openFile();
{

try {
FileReader fr=new FileReader(file);
int len=(int)file.length();
char[]buffer=new char[len];
fr.read(buffer,0,len);
fr.close();
text.setText(new String(buffer));
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
public static void main(String[] args) {
// TODO 自动生成方法存根
new ss();
}
public void actionPerformed(ActionEvent e) {
// TODO 自动生成方法存根
if(e.getSource()==openButton)
{
if(file!=null);
{
filechooser.setSelectedFile(file);
}
int returnVal=filechooser.showOpenDialog(this);
if(returnVal==JFileChooser.APPROVE_OPTION)
{
file=filechooser.getSelectedFile();
openFile();
}
}
if(e.getSource()==saveButton)
{
if(file!=null);
{
filechooser.setSelectedFile(file);

}
int returnVal=filechooser.showOpenDialog(this);
if(returnVal==JFileChooser.APPROVE_OPTION)
{
file=filechooser.getSelectedFile();
saveFile();
}
}
}

}
请教各位大哥哥,这里哪里错了
...全文
34 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

51,408

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧