📄 aboutdialog.java
字号:
package mynews;
import java.awt.Toolkit;
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.widgets.Button;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;
import com.swtdesigner.SWTResourceManager;
import org.eclipse.jface.dialogs.MessageDialog;
public class AboutDialog extends Dialog {
private Label label;
private Group aboutGroup;
private Button closeButton;
protected Object result;
protected Shell shell;
/**
* Create the dialog
* @param parent
* @param style
*/
public AboutDialog(Shell parent, int style) {
super(parent, style);
}
/**
* Create the dialog
* @param parent
*/
public AboutDialog(Shell parent) {
this(parent, SWT.NONE);
}
/**
* Open the dialog
* @return the result
*/
public Object open() {
createContents();
shell.open();
shell.layout();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
return result;
}
/**
* Create contents of the dialog
*/
protected void createContents() {
shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setSize(393, 214);
Toolkit kit = Toolkit.getDefaultToolkit();
shell.setLocation((kit.getScreenSize().width - 393) / 2, (kit.getScreenSize().height - 214) / 2);
shell.setText("About");
label = new Label(shell, SWT.NONE);
label.addMouseListener(new MouseAdapter() {
public void mouseDoubleClick(final MouseEvent e) {
MessageDialog.openInformation(shell, "OMG", "Oops!");
}
});
label.setImage(SWTResourceManager.getImage(AboutDialog.class, "/img/222.png"));
label.setBounds(0, 0, 136, 148);
aboutGroup = new Group(shell, SWT.NONE);
aboutGroup.setText("Info");
aboutGroup.setBounds(142, 23, 212, 108);
final Label authorIchuanLabel = new Label(aboutGroup, SWT.NONE);
authorIchuanLabel.setText("Author: iChuan");
authorIchuanLabel.setBounds(20, 45, 144, 14);
final Label emailIyanchuangmailcomLabel = new Label(aboutGroup, SWT.NONE);
emailIyanchuangmailcomLabel.setText("Email: iyanchuan@gmail.com");
emailIyanchuangmailcomLabel.setBounds(20, 65, 182, 14);
final Link eclipseorgLink = new Link(aboutGroup, SWT.NONE);
eclipseorgLink.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
result = "http://imchuan.cn/";
shell.close();
}
});
eclipseorgLink.setText("<a href=\"http://imchuan.cn/\" target=\"_blank\">http://imchuan.cn/</a>");
eclipseorgLink.setBounds(58, 85, 105, 15);
final Label webLabel = new Label(aboutGroup, SWT.NONE);
webLabel.setText("Web:");
webLabel.setBounds(20, 85, 32, 14);
final Label version01BetaLabel = new Label(aboutGroup, SWT.NONE);
version01BetaLabel.setText("Version: 0.1 beta.");
version01BetaLabel.setBounds(20, 24, 172, 14);
closeButton = new Button(shell, SWT.NONE);
closeButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
result = null;
shell.close();
}
});
closeButton.setText("Close");
closeButton.setBounds(242, 144, 112, 32);
shell.setTabList(new Control[] {closeButton, aboutGroup, label});
//
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -