I have a file, we can call it 'example.txt' and I've already called the file in my program. I want to add functionality to open the file when a JButton, myButton is clicked. This is my code so far:
myButton.setText("Button");
 File example_file = new File("~/path/to/example.txt");
 myButton.addActionListener(new java.awt.event ActionListener(){
   public void actionPerformed (java.awt.event.ActionEvent evt){
     myButtonActionPerformed(evt);
   }
 });
private void myButtonActionPerformed(java.awt.event.ActionEvent evt){
   //open the file
}
I'm sure there is a very simple way to do this, but I haven't been able to find anything.
 
     
     
    