📄 first.java
字号:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class first {
private static Button b1;
private static Text text;
/**
* Launch the application
* @param args
*/
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setLayout(new FormLayout());
shell.setSize(0, 0);
shell.setText("SWT Application");
//
shell.open();
final Label label = new Label(shell, SWT.BORDER);
final FormData fd_label = new FormData();
fd_label.left = new FormAttachment(0, 30);
fd_label.right = new FormAttachment(0, 55);
fd_label.bottom = new FormAttachment(0, 138);
fd_label.top = new FormAttachment(0, 125);
label.setLayoutData(fd_label);
label.setText("Label");
final Label label_1 = new Label(shell, SWT.NONE);
final FormData fd_label_1 = new FormData();
fd_label_1.bottom = new FormAttachment(0, 36);
fd_label_1.top = new FormAttachment(0, 23);
fd_label_1.right = new FormAttachment(0, 30);
fd_label_1.left = new FormAttachment(0, 5);
label_1.setLayoutData(fd_label_1);
label_1.setText("Label");
text = new Text(shell, SWT.BORDER);
final FormData fd_text = new FormData();
fd_text.bottom = new FormAttachment(0, 60);
fd_text.top = new FormAttachment(0, 41);
fd_text.right = new FormAttachment(0, 108);
fd_text.left = new FormAttachment(0, 35);
text.setLayoutData(fd_text);
b1 = new Button(shell, SWT.NONE);
b1.addMouseListener(new MouseAdapter() {
public void mouseDoubleClick(MouseEvent arg0) {
b1.setVisible(false);
}
public void mouseDown(MouseEvent arg0) {
b1.setVisible(false);
}
});
final FormData gd_b1 = new FormData();
gd_b1.bottom = new FormAttachment(0, 100);
gd_b1.top = new FormAttachment(0, 50);
gd_b1.right = new FormAttachment(0, 426);
gd_b1.left = new FormAttachment(0, 185);
b1.setLayoutData(gd_b1);
b1.setText("B1");
final Menu menu = new Menu(shell, SWT.BAR);
shell.setMenuBar(menu);
final MenuItem menuItem_2 = new MenuItem(menu, SWT.CASCADE);
menuItem_2.setText("Menu Item");
final Menu menu_1 = new Menu(menuItem_2);
menuItem_2.setMenu(menu_1);
final MenuItem menuItem_3 = new MenuItem(menu_1, SWT.CASCADE);
menuItem_3.setText("Menu Item");
final Menu menu_2 = new Menu(menuItem_3);
menuItem_3.setMenu(menu_2);
final MenuItem menuItem_4 = new MenuItem(menu_2, SWT.NONE);
menuItem_4.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
b1.setText("asa");
}
});
menuItem_4.setText("Menu Item");
final MenuItem menuItem_1 = new MenuItem(menu_1, SWT.NONE);
menuItem_1.setText("Menu Item");
final MenuItem menuItem = new MenuItem(menu, SWT.CASCADE);
menuItem.setText("Menu Item");
final Menu menu_3 = new Menu(menuItem);
menuItem.setMenu(menu_3);
final MenuItem menuItem_5 = new MenuItem(menu_3, SWT.NONE);
menuItem_5.setText("Menu Item");
shell.layout();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -