- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 JFileChooser 中工作,要从另一个类中选择文件,我不关心按钮的外观,但当有人单击它时。它应该显示 JFileChooser 选择 srt 文件(类似于文本文件,但另一种类型)并且它应该读取它。
这是我的第一个类
package AnimeAid;
import java.io.*;
import javax.swing.*;
public class ReadFile {
private File ourFile= null;
private static final JFileChooser selectSrtFile = new JFileChooser();
String filePath = "";
public ReadFile(){
}
public File getSelectFile(){
selectSrtFile.setFileSelectionMode(JFileChooser.FILES_ONLY);
selectSrtFile.showSaveDialog(null);
ourFile = selectSrtFile.getSelectedFile();
filePath = ourFile.getAbsolutePath();
return ourFile;
}
public String readFileInput(){
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(getSelectFile()), "UTF-8"));
String line;
while ((line = reader.readLine()) != null)
{
System.out.println(line);
}
}catch(IOException ex){
return "there is wrong";
}
return "file is added";
}
}
扫描的类
package AnimeAid;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
* @author isslam
*/
public class GuiInterface extends JFrame {
JTable table;
JButton is;
ReadFile t;
public GuiInterface(String title){
setSize(900, 700);
setTitle(title);
setDefaultCloseOperation(GuiInterface.EXIT_ON_CLOSE);
is = new JButton();
t = new ReadFile();
Container cp = getContentPane();
cp.add(is);
is.addActionListener(new addButtonWatcher());
}
private class addButtonWatcher implements ActionListener{
@Override
public void actionPerformed(ActionEvent a){
Object buttonPressed=a.getSource();
if(buttonPressed.equals(is))
{
t.getSelectFile();
}
}
}
}
错误信息
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: animeaid.GuiInterface
at animeaid.main.main(main.java:15)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
最佳答案
看起来你的两个类有不同的包:
package animeFactor;
^
和
package animefactor;
^
我相信 Java 包名称区分大小写,因此尽管您(可能)已将这两个文件放在同一个文件夹中,GuiInterface
类仍无法使用 ReadFile
code> 类而不导入它。
要么将包定义更改为相同,要么向 GuiInterface
添加导入语句:
import animeFactor.ReadFile;
关于java - 使用 JFileChooser 选择 srt 文件并读取它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21124689/
我正在对 JFileChooser UI 进行一些定制。我正在寻找 JFilechooser 的渐变背景。我所能做的只是一个自定义的 JFilechooser,但我不确定如何将 gardientbac
我想将 JComboBox 添加到 JFileChooser 中。 我尝试扩展 JFileChooser 并手动添加组合框。我实际上设法做到了这一点,但是从 JFileChooser 对话框中删除了文
我试图在文件选择器对话框中打开一个文件,但是,当我打开一个文件或只是关闭对话框时。对话框再次出现,我必须关闭它两次。这是我的代码,不知道有什么问题 private void jMenuItem1Act
如何强制我的 JFileChooser 具有垂直滚动的单列而不是水平滚动的多列? 最佳答案 如果我理解您的要求,您也许可以使用 JList#setLayoutOrientation(JList.VER
所以我得到了这段非常基本的代码,它使用文件名过滤器初始化 JFileChooser。目前您应该只能看到 .txt 文件,稍后我想使用自定义文件名。 JFileChooser dialog = new
我想在我的程序中使用 JFileChooser 来选择目录并处理它。但是,无论我为文件选择器使用什么 FileFilter,选择目录时 Open 按钮都是锁定的。下面是我的 FileFilter 的代
我创建了一个文件,然后需要将其另存为 .docx 扩展名,但我的代码将其另存为 .txt,如何更改扩展名? JFileChooser saveFile = new JFileChooser()
我使用 JFileChooser 让用户保存文件。但我不希望用户选择一个名称来保存文件。不得启用名称文本字段。 我阅读了文档,但没有找到这样的方法或属性。 最佳答案 评论中的Squiddie给你推荐了
我想更改“查看菜单”菜单下的“列表”按钮文本,但我找不到方法。这是文件选择器窗口的图片。 JFileChooser dialog window 我尝试了这些,但没有成功: UIManager.put(
我有以下 Java 8 Swing 代码: JButton button = new JButton("Browse"); button.addActionListener(new ActionLis
继我之前的两篇文章之后here另一个one here ,以下代码打开常规文件浏览器而不是扩展的文件浏览器: public class GuiHandler extends javax.swing.JF
我开发了一个程序,用于计算文件中的行数,如下所示 Scanner in=new Scanner(System.in); System.out.println("Enter the Drive
我的程序允许您保存已制作的图像。我只需要将其另存为 png 即可。 我目前有: ... File file = fc.getSelectedFile(); try{ ImageIO.write(res
我想自定义我的 JFileChooser,这样我不想在底部说“文件夹名称”,而是将其设置为“图片名称”,并且在文本字段中我不希望它根据我所在的位置进行更改我点击,我希望它一直保持空白。无论如何我可以做
在我的 java 应用程序中,有一个浏览按钮。单击浏览按钮时,弹出文件选择器以选择文件。当我通过单击右上角的十字标记而不选择文件来关闭文件选择器时,它会给出一个异常,提示“线程“AWT-EventQu
阅读 documentation 后我没有看到使用 showDialog() 时使对话框模式化的好方法。 . 是否有一种好方法可以使 JFileChooser 实例成为文档模式而不是应用程序模式? 最
我正在使用 JFileChooser,我想让它在单击 fileItem1 时显示文件选择对话框。这是我的 SwingMenu 类。 问题:我在 showFileChooser 方法中遗漏/做错了什么?
我一直在尝试使用 JFileChooser,但遇到程序无法停止运行的问题,这是我的代码: import java.io.File; import javax.swing.JFileChooser; i
如何在屏幕中央显示 JFile-Chooser。使用 ToolKit 的常规方法不起作用。 最佳答案 查看 Javadoc 中的方法 JFileChooser#showDialog(Component
我对 Swing 和 AWT 还很陌生。虽然我有Java开发经验。我正在尝试使用 JFileChooser 读取文件并获取主方法中的内容。所有 Swing 和 AWT 的大师请帮助我确定我缺少什么。
我是一名优秀的程序员,十分优秀!