我刚开始使用Java basic并且遇到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();
}
});
}
答案 0 :(得分:1)
您可能导入错误的FileDialog
课程 - 您需要导入org.eclipse.swt.widgets.FileDialog
而不是 java.awt.FileDialog