Import org.eclipse.jface.dialogs.messagedialog;
Import org.eclipse.swt.events.selectionadapter;
Import org.eclipse.swt.events.selectionevent;
Import org.eclipse.swt.widgets.display;
Import org.eclipse.swt.widgets.shell;
Import org.eclipse.swt.widgets.menu;
Import org.eclipse.swt.swt;
Import org.eclipse.swt.widgets.menuitem;
Common class test {
Protective shell shell;
/**
* Start the application.
* @param args
*/
Public static void main(String[] args) {
Try {
Test window = new test ();
window . open();
Catch (exception e) {
e . printstacktrace();
}
}
/**
* Open the window.
*/
public void open() {
display display = display . get default();
create contents();
shell . open();
shell . layout();
And (! shell.isDisposed()) {
If (! display.readAndDispatch()) {
display . sleep();
}
}
}
/**
* Create the contents of the window.
*/
Protected void createContents() {
Shell = new Shell();
shell.setSize(450,300);
Shell.settext ("swt application");
Menu menu = new menu (Shell, SWT. Right);
Shell.setMenuBar (menu);
MenuItem menuItem = new MenuItem (menu, SWT. Cascade);
menuitem . settext(" \ u4e 3b \ u83DC \ u 5355 1 ");
Menu menu_ 1 = new menu (menuitem);
menuitem . setmenu(menu _ 1);
MenuItem MenuItem _ 2 = new MenuItem(menu _ 1,SWT。 Cascade);
menuItem _ 2 . settext(" \ u4E0B \ u62c 9 \ u83DC \ u 5355 1. 1 ");
Menu menu_3 = new menu (menuitem _ 2);
menuItem _ 2 . setmenu(menu _ 3);
MenuItem MenuItem _ 3 = new MenuItem(menu _ 3,SWT。 Check);
menuItem _ 3 . settext(" \ u590D \ u 9009 \ u 6846 1 ");
menuItem _ 3 . addselectionlistener(new selection adapter(){
public void widgetSelected(selection event e){
Message dialog box. Open the message (shell, "menu listener", "You selected:"+e.getsource () ");
}
});
MenuItem MenuItem _ 4 = new MenuItem(menu _ 3,SWT。 Check);
menuItem _ 4 . settext(" \ u590D \ u 9009 \ u 68462 ");
menuItem _ 4 . addselectionlistener(new selection adapter(){
public void widgetSelected(selection event e){
Message dialog box. Open the message (shell, "menu listener", "You selected:"+e.getsource () ");
}
});
MenuItem MenuItem _ 5 = new MenuItem(menu _ 3,SWT。 Check);
menuItem _ 5 . settext(" \ u590D \ u 9009 \ u 68463 ");
menuItem _ 5 . addselectionlistener(new selection adapter(){
public void widgetSelected(selection event e){
Message dialog box. Open the message (shell, "menu listener", "You selected:"+e.getsource () ");
}
});
New menu item (menu_3, SWT. Separator);
MenuItem MenuItem _ 6 = new MenuItem(menu _ 3,SWT。 Radio);
menuItem _ 6 . settext(" \ u 5355 \ u 9009 \ u 6846 1 ");
MenuItem MenuItem _ 7 = new MenuItem(menu _ 3,SWT。 Radio);
menuItem _ 7 . settext(" \ u 5355 \ u 9009 \ u 68462 ");
MenuItem MenuItem _ 8 = new MenuItem(menu _ 1,SWT。 None);
menuItem _ 8 . settext(" \ u4E0B \ u62c 9 \ u83DC \ u 5355 1.2 ");
MenuItem MenuItem _ 9 = new MenuItem(menu _ 1,SWT。 None);
menuItem _ 9 . settext(" \ u 4 e0b \ u 6765 \ u 83 DC \ u 5355 1.3 ");
MenuItem menuItem_ 1 = new menu item (menu, SWT. Cascade);
menuItem _ 1 . settext(" \ u 4 e3b \ u 83 DC \ u 53552 ");
Menu menu_2 = new menu (menuitem _1);
menuItem _ 1 . setmenu(menu _ 2);
MenuItem menuItem_ 10 = new MenuItem(menu_2, SWT. None);
menuItem _ 10 . settext(" \ u 4 e0b \ u62c 9 \ u83DC \ u 53552. 1 ");
Menuitem menuitem _11= new MenuItem(menu_2, SWT. None);
menuItem _ 1 1 . settext(" \ u 4 e0b \ u62c 9 \ u 83 DC \ u 53552.2 ");
}
}
This is written in SWT and is very easy to use. The specific application is a menuitem for adding the selected listener. Here, when the check box is selected, a message box will pop up, clearly showing that this option is selected.