我有一个文件,我们可以将其命名为“example.txt”,并且我已经在程序中调用了该文件。我想添加在 JButton myButton
时打开文件的功能被点击。这是我到目前为止的代码:
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
}
我确信有一个非常简单的方法可以做到这一点,但我还没有找到任何东西。
最佳答案
关于java - 如何使用 JButton 打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29186609/