📄 inforcarddialog.java
字号:
package com.jim.client;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.jim.database.JIMUser;
import com.swtdesigner.SWTResourceManager;
public class InforCardDialog extends Dialog {
protected String result;
protected Shell shell;
protected Text pwdText;
protected Combo faceCombo;
protected Text inforText;
protected Text numText;
protected Text emailText;
protected Text cityText;
protected Text ageText;
protected Text nameText;
protected Text nickText;
private boolean readOnly;
private Integer key = new Integer(0);
protected Button maleButton;
protected Button femaleButton;
private Button updateButton;
public static String UPDATE = "更 新";
public static String REGISTER = "确 定";
private String op;
/**
* Create the dialog
* @param parent
* @param style
*/
public InforCardDialog(Shell parent, int style,String op,boolean readonly) {
super(parent, style);
this.op = op;
this.readOnly = readonly;
createContents();
}
/**
* Create the dialog
* @param parent
*/
public InforCardDialog(Shell parent,String op,boolean readOnly) {
this(parent, SWT.NONE,op,readOnly);
}
/**
* Open the dialog
* @return the result
*/
public String open() {
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.setText("【信息】");
shell.setSize(408, 281);
final GridLayout gridLayout = new GridLayout();
gridLayout.marginRight = 5;
gridLayout.marginLeft = 5;
gridLayout.marginHeight = 10;
gridLayout.numColumns = 5;
shell.setLayout(gridLayout);
shell.setImage(SWTResourceManager.getImage(InforCardDialog.class, "resources/1.bmp"));
final Label numLabel = new Label(shell, SWT.NONE);
final GridData gridData_3 = new GridData(SWT.CENTER, SWT.CENTER, false, false);
gridData_3.horizontalIndent = 5;
numLabel.setLayoutData(gridData_3);
numLabel.setText(" 号 码 :");
numText = new Text(shell, SWT.READ_ONLY | SWT.BORDER);
numText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,2,1));
final Label headIxLabel = new Label(shell, SWT.NONE);
final GridData gridData_3_1 = new GridData(SWT.CENTER, SWT.CENTER, false, false);
gridData_3_1.horizontalIndent = 5;
headIxLabel.setLayoutData(gridData_3_1);
headIxLabel.setText(" 头 像 :");
faceCombo = new Combo(shell, SWT.READ_ONLY);
faceCombo.setItems(new String[] {"头像-1", "头像-2", "头像-3"});
faceCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
faceCombo.setEnabled(readOnly);
final Label pwdLabel = new Label(shell, SWT.NONE);
pwdLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
pwdLabel.setText(" 密 码 :");
pwdText = new Text(shell, SWT.PASSWORD | SWT.BORDER);
pwdText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
pwdText.setEditable(readOnly);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
final Label nickLabel = new Label(shell, SWT.NONE);
final GridData gridData = new GridData(SWT.CENTER, SWT.CENTER, false, false);
gridData.horizontalIndent = 5;
nickLabel.setLayoutData(gridData);
nickLabel.setText(" 昵 称 :");
nickText = new Text(shell, SWT.BORDER);
nickText.setTabs(0);
nickText.setTextLimit(10);
nickText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
nickText.setEditable(readOnly);
final Label nameLabel = new Label(shell, SWT.NONE);
final GridData gridData_1 = new GridData(SWT.CENTER, SWT.CENTER, false, false);
gridData_1.horizontalIndent = 5;
nameLabel.setLayoutData(gridData_1);
nameLabel.setText(" 姓 名 :");
nameText = new Text(shell, SWT.BORDER);
nameText.setTextLimit(10);
nameText.setTabs(0);
nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
nameText.setEditable(readOnly);
final Label genderLabel = new Label(shell, SWT.NONE);
final GridData gridData_2 = new GridData(SWT.CENTER, SWT.CENTER, false, false);
gridData_2.horizontalIndent = 5;
genderLabel.setLayoutData(gridData_2);
genderLabel.setText(" 性 别 :");
maleButton = new Button(shell, SWT.RADIO);
maleButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
maleButton.setText("男");
maleButton.setEnabled(readOnly);
femaleButton = new Button(shell, SWT.RADIO);
femaleButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
femaleButton.setText("女");
femaleButton.setEnabled(readOnly);
final Label ageLabel = new Label(shell, SWT.NONE);
final GridData gridData_2_1 = new GridData(SWT.CENTER, SWT.CENTER, false, false);
gridData_2_1.horizontalIndent = 5;
ageLabel.setLayoutData(gridData_2_1);
ageLabel.setText(" 年 龄 :");
ageText = new Text(shell, SWT.BORDER);
ageText.setTextLimit(4);
ageText.setTabs(0);
ageText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
ageText.setEditable(readOnly);
final Label cityLabel = new Label(shell, SWT.NONE);
cityLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
cityLabel.setText(" 城 市 :");
cityText = new Text(shell, SWT.BORDER);
cityText.setTextLimit(20);
cityText.setTabs(0);
cityText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
cityText.setEditable(readOnly);
final Label emailLabel = new Label(shell, SWT.NONE);
emailLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
emailLabel.setText(" 邮 箱 :");
emailText = new Text(shell, SWT.BORDER);
emailText.setTextLimit(20);
emailText.setTabs(0);
emailText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
emailText.setEditable(readOnly);
final Label inforLabel = new Label(shell, SWT.NONE);
inforLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
inforLabel.setText(" 简 介 :");
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
inforText = new Text(shell, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.WRAP);
inforText.setTextLimit(200);
inforText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
inforText.setEditable(readOnly);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
updateButton = new Button(shell, SWT.NONE);
updateButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent se) {
RegOrUp(se);
}
});
final GridData gridData_4 = new GridData(SWT.CENTER, SWT.CENTER, false, false);
gridData_4.widthHint = 68;
updateButton.setLayoutData(gridData_4);
updateButton.setText(op);
updateButton.setEnabled(readOnly);
final Button closeButton = new Button(shell, SWT.NONE);
closeButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
closeWin(event);
}
});
final GridData gridData_5 = new GridData(SWT.CENTER, SWT.CENTER, false, false);
gridData_5.widthHint = 68;
closeButton.setLayoutData(gridData_5);
closeButton.setText("关 闭");
}
protected void closeWin(SelectionEvent event) {
MainWin.removeWin(key);
shell.close();
}
protected void RegOrUp(SelectionEvent se) {
if(updateButton.getText().equals(REGISTER)){
JIMUser u = new JIMUser();
u.setNicknm(nickText.getText());
u.setEmail(emailText.getText());
u.setName(nameText.getText());
u.setGender(maleButton.getSelection() ? JIMUser.MALE : JIMUser.FEMALE);
u.setPwd(pwdText.getText());
u.setAge(Short.valueOf(ageText.getText()));
u.setInfor(inforText.getText());
u.setPicindex((short)faceCombo.getSelectionIndex());
int jimNum = 0;
jimNum = MainWin.client.register(u);
if(jimNum != 0){
result = "OK";
numText.setText(""+jimNum);
MessageBox mb = new MessageBox(shell,SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage("注册成功\n你的JIM号码为 ["+jimNum+"]");
mb.open();
shell.close();
}
else{
result = "ERROR";
MessageBox mb = new MessageBox(shell,SWT.ICON_ERROR | SWT.OK);
mb.setMessage("注册失败!");
mb.open();
}
}else if(updateButton.getText().equals(UPDATE)){
JIMUser u = MainWin.client.getUser();
u.setNicknm(nickText.getText());
u.setEmail(emailText.getText());
u.setName(nameText.getText());
u.setGender(maleButton.getSelection() ? JIMUser.MALE : JIMUser.FEMALE);
u.setPwd(pwdText.getText());
u.setAge(Short.valueOf(ageText.getText()));
u.setInfor(inforText.getText());
u.setPicindex((short)faceCombo.getSelectionIndex());
String status = MainWin.client.updateInfo(u);
MessageBox mb = new MessageBox(shell,SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(status);
mb.open();
shell.close();
}
}
public void setOperation(String text){
updateButton.setText(text);
}
public Integer getKey() {
return key;
}
public void setKey(Integer key) {
this.key = key;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -