gpt4 book ai didi

java - SWT 文件对话框错误 : constructor FileDialog is undefined

转载 作者:行者123 更新时间:2023-11-30 08:05:25 26 4
gpt4 key购买 nike

我刚刚开始学习 Java 基础知识,并且在使用 SWT FileDialog 时遇到了这个问题。 Eclipse 总是返回此错误:构造函数 FileDialog(Shell, int) 未定义

以下是完整代码,请帮忙指教一下?

public class FormObject2 {

protected Shell shell;
private Text txtComboBoxItem;
private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
private Text taOne;

/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
FormObject2 window = new FormObject2();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}

/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(481, 364);
shell.setText("SWT Application");

Menu menu = new Menu(shell, SWT.BAR);
shell.setMenuBar(menu);

MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE);
mntmFile.setText("File");

Menu menu_1 = new Menu(mntmFile);
mntmFile.setMenu(menu_1);

MenuItem mntmOpen = new MenuItem(menu_1, SWT.NONE);
mntmOpen.setAccelerator(1);
mntmOpen.setText("Open");
mntmOpen.setAccelerator(SWT.MOD1+ 'O');

MenuItem mntmSave = new MenuItem(menu_1, SWT.NONE);
mntmSave.setAccelerator(1);
mntmSave.setText("Save");

MenuItem mntmEdit = new MenuItem(menu, SWT.CASCADE);
mntmEdit.setText("Edit");

Menu menu_2 = new Menu(mntmEdit);
mntmEdit.setMenu(menu_2);

MenuItem mntmExit = new MenuItem(menu_2, SWT.NONE);
mntmExit.setText("Exit");

mntmOpen.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(shell, SWT.MULTI);
dialog.setFilterPath("C:\\Logs");
dialog.setFilterExtensions(new String[]{"*.txt", "*.pdf", "*.*"});
dialog.setFilterNames(new String[]{ "Rich Text Format", "HTML Document", "Any"});
dialog.open();
}
});
}

最佳答案

您可能导入了错误的 FileDialog 类 - 您需要导入 org.eclipse.swt.widgets.FileDialog 不是 java.awt.FileDialog

关于java - SWT 文件对话框错误 : constructor FileDialog is undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31204030/

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