add(ta); } public void actionPerformed(ActionEvent e) { if(e.getSource()==open){ openFile(); } } void openFile(){ JFileChooser fc=new JFileChooser(); int i=fc.showOpenDialog(this); if(i==JFileChooser.APPROVE_OPTION){ File f=fc.getSelectedFile(); String filepath=f.getPath(); displayContent(filepath); } } void displayContent(String fpath){ try{ BufferedReader br=new BufferedReader(new String s1="",s2=""; while((s1=br.readLine())!=null){ s2+=s1+"\n"; } ta.setText(s2); br.close(); }catch (Exception e) {e.printStackTrace(); } } public static void main(String[] args) { OpenMenu om=new OpenMenu(); om.setSize(800,800); om.setLayout(null); om.setVisible(true); om.setDefaultCloseOperation(EXIT_ON_CLOSE);
add(ta); } public void actionPerformed(ActionEvent e) { if(e.getSource()==open){ openFile(); } } void openFile(){ JFileChooser fc=new JFileChooser(); int i=fc.showOpenDialog(this); if(i==JFileChooser.APPROVE_OPTION){ File f=fc.getSelectedFile(); String filepath=f.getPath(); displayContent(filepath); } } void displayContent(String fpath){ try{ BufferedReader br=new BufferedReader(new String s1="",s2=""; while((s1=br.readLine())!=null){ s2+=s1+"\n"; } ta.setText(s2); br.close(); }catch (Exception e) {e.printStackTrace(); } } public static void main(String[] args) { OpenMenu om=new OpenMenu(); om.setSize(800,800); om.setLayout(null); om.setVisible(true); om.setDefaultCloseOperation(EXIT_ON_CLOSE);
1.Enosis_JavaTutorial.docx