File file; JTextPane textpane; FileInputStream readStream; JScrollPane scroll; public FileFrame()
super ("文件浏览"); JMenu fileM = new JMenu("文件"); OpenAction open = new OpenAction (); SaveAction clear = new SaveAction (); ExitAction exit = new ExitAction(); JMenuBar mb = new JMenuBar(); fileM.add(open); fileM.add(clear); fileM.add(exit); mb.add(fileM); textpane=new JTextPane(); scroll=new JScrollPane(textpane); getContentPane().add(scroll); getContentPane().addJMenuBar(mb);
class OpenAction extends AbstractAction
public OpenAction ()
super("打开");
public void actionPerformed( ActionEvent e )
JFileChooser chooser=new JFileChooser(); int state=chooser.showOpenDialog(null); file=chooser.selectedFile(); if(file!=null&&state==JFileChooser.APPROVE_OPTION)