gpt4 book ai didi

java - @Override 在 SwingWorker 方法中不起作用

转载 作者:行者123 更新时间:2023-11-30 03:57:29 25 4
gpt4 key购买 nike

经过多次尝试使用 Worker 类扩展 SwingWorker 类来查找 @Override 的问题后,我希望有人能帮助我找到答案,我的旧代码是:

这段代码负责读取文件并显示JTable内的信息,但是速度很慢,所以我需要使用swingworker,所以我更新了代码(看下一个代码)

private DefaultTableModel createModel(String srtPath) {
//int maxLine = ReadFile.maxLine(srtPath); // debug
//Object[][] data = new Object[maxLine][];
//System.out.println(maxLine); // debug
DefaultTableModel model = new DefaultTableModel(columnNames, 0);
ArrayList<String> ends = ReadFile.getFileEndingTime(srtPath);
ArrayList<String> starts = ReadFile.getFileStartingTime(srtPath);
ArrayList<String> subs = ReadFile.readSubtitles(srtPath);
ArrayList<String> lins = ReadFile.ArraylineLengths(srtPath);
for (int i = 0; i < ReadFile.maxLine(srtPath); i++) {
//System.out.println(lins.get(i)+" "+starts.get(i)+" "+ ends.get(i)+" "+ subs.get(i));
model.addRow(new Object[] {lins.get(i), starts.get(i), ends.get(i), subs.get(i)});
}
return model;

现在为了使用 SwingWorker,我应用了此更改

  @Override
class Worker extends SwingWorker<DefaultTableModel, Void> {
private final String srtPath;
private final JTable table;
DefaultTableModel model;
public Worker(String srtPath, JTable table) {
this.srtPath = srtPath;
this.table = table;
}

protected DefaultTableModel doInBackground(String srtPath) {
model = new DefaultTableModel(columnNames, 0);
ArrayList<String> ends = ReadFile.getFileEndingTime(srtPath);
ArrayList<String> starts = ReadFile.getFileStartingTime(srtPath);
ArrayList<String> subs = ReadFile.readSubtitles(srtPath);
ArrayList<String> lins = ReadFile.ArraylineLengths(srtPath);
for (int i = 0; i < ReadFile.maxLine(srtPath); i++) {
model.addRow(new Object[] {lins.get(i), starts.get(i), ends.get(i), subs.get(i)});
}
return model;
}
@Override
protected void done() {
table.setModel(model);
table.setFillsViewportHeight(true);
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
TableColumn columnA = table.getColumn("#");
columnA.setMinWidth(10);
columnA.setMaxWidth(40);
TableColumn columnB= table.getColumn("Start");
columnB.setMinWidth(80);
columnB.setMaxWidth(90);
TableColumn columnC= table.getColumn("End");
columnC.setMinWidth(80);
columnC.setMaxWidth(90);
}
}

这段代码是我的操作方法

Action openAction = new AbstractAction("Open Subtitle", openIcon) {
@Override
public void actionPerformed(ActionEvent e) {
ourFileSelector.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
ourFileSelector.showSaveDialog(null);
ourSrtFile = ourFileSelector.getSelectedFile();
srtPath = ourSrtFile.getAbsolutePath();
Worker p = new Worker(srtPath, table);
p.execute();


}
};

我遇到错误

    C:\Users\isslam\Documents\NetBeansProjects\AnimeAid\src\animeaid\GuiInterface.java:241: error: annotation type not applicable to this kind of declaration
@Override
C:\Users\isslam\Documents\NetBeansProjects\AnimeAid\src\animeaid\GuiInterface.java:242: error: GuiInterface.Worker is not abstract and does not override abstract method doInBackground() in SwingWorker
class Worker extends SwingWorker<DefaultTableModel, Void> {
Note: C:\Users\isslam\Documents\NetBeansProjects\AnimeAid\src\animeaid\GuiInterface.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

最佳答案

不要@Override该类。仅对方法使用@Override。

关于java - @Override 在 SwingWorker 方法中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22816564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com