主题:求助怎么在不同的容器里取值
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
public class QQ {
private Composite composite;
/**
* Launch the application
* @param args
*/
private StackLayout stackLayout=new StackLayout();
private Composite yourDataComp;
private Composite otherComp;
private List selectList;
private Composite rightComp;
public Composite createYourDataComp(Composite rightComp)
{
Composite composite=new Composite(rightComp,SWT.NONE);
composite.setLayout(new GridLayout(6,false));
new Label(composite,SWT.NONE).setText("用户号码:");
Text text=new Text(composite,SWT.BORDER);
text.setLayoutData(createGridData(GridData.FILL_HORIZONTAL,3));
Composite photoComp=new Composite(composite,SWT.BORDER);
photoComp.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL|GridData.VERTICAL_ALIGN_FILL,2,4));
photoComp.setLayout(new GridLayout(2,false));
{
Composite tempComp=new Composite(photoComp,SWT.BORDER);
tempComp.setLayoutData(new GridData(50,50));
Button selPhotoButton=new Button(photoComp,SWT.ARROW|SWT.DOWN);
selPhotoButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));
Button updataButton=new Button(photoComp,SWT.NONE);
updataButton.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,2));
updataButton.setText("升级程序");
}
new Label(composite,SWT.NONE).setText("用户昵称");
Text nicknameText=new Text(composite,SWT.BORDER);
nicknameText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,3));
new Label(composite,SWT.NONE).setText("个性签名");
Text attachNameText=new Text(composite,SWT.BORDER);
attachNameText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,3));
new Label(composite,SWT.NONE).setText("等 级");
{
Composite tempComp=new Composite(composite,SWT.BORDER);
GridData gridData=new GridData(GridData.FILL_HORIZONTAL|GridData.VERTICAL_ALIGN_BEGINNING);
gridData.horizontalSpan=3;
gridData.heightHint=20;
tempComp.setLayoutData(gridData);
}
new Label(composite,SWT.READ_ONLY).setText("性 别:");
Combo sexCombo=new Combo(composite,SWT.NONE);
sexCombo.add("男");
sexCombo.add("女");
sexCombo.select(0);
new Label(composite,SWT.NONE).setText("姓名:");
Text nameText=new Text(composite,SWT.BORDER);
nameText.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
new Label(composite,SWT.NONE).setText("年龄:");
Text oldText=new Text(composite,SWT.BORDER);
oldText.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
new Label(composite,SWT.NONE).setText("毕业院校:");
Text schoolText=new Text(composite,SWT.BORDER);
schoolText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,3));
new Label(composite,SWT.READ_ONLY).setText("生肖:");
Combo animalCombo=new Combo(composite,SWT.BORDER);
animalCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
animalCombo.setItems(new String[]{"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"});
animalCombo.select(0);
new Label(composite,SWT.NONE).setText("职业:");
Text jobText=new Text(composite,SWT.BORDER);
jobText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,3));
new Label(composite,SWT.READ_ONLY).setText("星座:");
Combo constellationCombo=new Combo(composite,SWT.BORDER);
constellationCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
constellationCombo.setItems(new String[]{"白 羊 座","金 牛 座","双 子 座","巨 蟹 座","狮 子 座","处 女 座","天 秤 座","天 蝎 座","射 手 座","摩 羯 座","水 瓶 座","双 鱼 座"});
constellationCombo.select(0);
Label introLabel=new Label(composite,SWT.NONE);
introLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
introLabel.setText("个人说明:");
Text introText=new Text(composite,SWT.BORDER|SWT.WRAP);
introText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL|GridData.FILL_VERTICAL,5));
String yhhm=text.getText();
String yhnc=nicknameText.getText();
String gxqm=attachNameText.getText();
String xb=sexCombo.getItems().toString();
String xm=nameText.getText();
String nl=oldText.getText();
String sx=animalCombo.getItems().toString();
String byyx=schoolText.getText();
String zy=jobText.getText();
String grsm=introText.getText();
String xz=constellationCombo.getItems().toString();
return composite;
}
public static void main(String[] args) {
try
{
QQ window=new QQ();
window.open();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void open()
{
Display display = Display.getDefault();
Shell shell = new Shell();
shell.setSize(550, 350);
shell.setText("个人设计");
//
shell.setLayout(new GridLayout());
{
SashForm sashForm=new SashForm(shell,SWT.BORDER);
sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
{
selectList=new List(sashForm,SWT.BORDER);
selectList.setItems(new String[]{"个人资料","联系方式"});
selectList.addMouseListener(new MyMouseLister());
}
{
rightComp=new Composite(sashForm,SWT.NONE);
rightComp.setLayout(stackLayout);
yourDataComp=createYourDataComp(rightComp);
otherComp=createOtherComp(rightComp);
stackLayout.topControl = composite;
}
sashForm.setWeights(new int[]{1,4});
}
{
Composite buttonComp=new Composite(shell,SWT.BORDER);
GridData gridData=new GridData();
gridData.horizontalAlignment=GridData.END;
buttonComp.setLayoutData(gridData);
RowLayout rowLayout=new RowLayout();
rowLayout.spacing=15;
buttonComp.setLayout(rowLayout);
new Button(buttonComp,SWT.NONE).setText(" 确定 ");
new Button(buttonComp,SWT.NONE).setText(" 取消 ");
Button button1=new Button(buttonComp,SWT.NONE);
button1.setText(" 应用 ");
button1.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
//读取用户数据写入数据库
//数据库连接
DBControl dbc=new DBControl();
String insertSQL="INSERT INTO grxi(yhhm,yhnc,gxqm,xb,xm,nl,sx,byyx,zy,grsm,xz)VALUES("+"'"+yhhm+"','"+nicknameText.getText()+"','"+attachNameText.getText()+"','"+sexCombo.getItems()+"','"+nameText.getText()+"','"+oldText.getText()+"',"+animalCombo.getItems()+"','"+schoolText.getText()+"','"+jobText.getText()+"','"+introText.getText()+"','"+constellationCombo.getItems()+"')";
boolean suc1=false;
suc1=dbc.insertSQL(insertSQL);
if(suc1)
{
MessageDialog.openInformation((Shell) composite,null,"注册成功");
}
else{
MessageDialog.openInformation((Shell) composite,null,"注册失败");
}
}
});
}
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
private Composite createOtherComp(Composite rightComp){
composite=new Composite(rightComp,SWT.NONE);
composite.setLayout(new FillLayout());
new Label(composite,SWT.NONE).setText("联系方式面板");
return composite;
}
private GridData createGridData(int style,int horizontalSpan){
GridData gridData=new GridData(style);
gridData.horizontalSpan=horizontalSpan;
return gridData;
}
private GridData createGridData(int style,int horizontalSpan,int verticalSpan){
GridData gridData=new GridData(style);
gridData.horizontalSpan=horizontalSpan;
gridData.verticalSpan=verticalSpan;
return gridData;
}
private class MyMouseLister extends MouseAdapter{
public void mouseDown(MouseEvent e){
int selectionIndex=selectList.getSelectionIndex();
if(selectionIndex==0)
stackLayout.topControl=yourDataComp;
else
stackLayout.topControl=otherComp;
rightComp.layout();
}
};
}
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
public class QQ {
private Composite composite;
/**
* Launch the application
* @param args
*/
private StackLayout stackLayout=new StackLayout();
private Composite yourDataComp;
private Composite otherComp;
private List selectList;
private Composite rightComp;
public Composite createYourDataComp(Composite rightComp)
{
Composite composite=new Composite(rightComp,SWT.NONE);
composite.setLayout(new GridLayout(6,false));
new Label(composite,SWT.NONE).setText("用户号码:");
Text text=new Text(composite,SWT.BORDER);
text.setLayoutData(createGridData(GridData.FILL_HORIZONTAL,3));
Composite photoComp=new Composite(composite,SWT.BORDER);
photoComp.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL|GridData.VERTICAL_ALIGN_FILL,2,4));
photoComp.setLayout(new GridLayout(2,false));
{
Composite tempComp=new Composite(photoComp,SWT.BORDER);
tempComp.setLayoutData(new GridData(50,50));
Button selPhotoButton=new Button(photoComp,SWT.ARROW|SWT.DOWN);
selPhotoButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));
Button updataButton=new Button(photoComp,SWT.NONE);
updataButton.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,2));
updataButton.setText("升级程序");
}
new Label(composite,SWT.NONE).setText("用户昵称");
Text nicknameText=new Text(composite,SWT.BORDER);
nicknameText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,3));
new Label(composite,SWT.NONE).setText("个性签名");
Text attachNameText=new Text(composite,SWT.BORDER);
attachNameText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,3));
new Label(composite,SWT.NONE).setText("等 级");
{
Composite tempComp=new Composite(composite,SWT.BORDER);
GridData gridData=new GridData(GridData.FILL_HORIZONTAL|GridData.VERTICAL_ALIGN_BEGINNING);
gridData.horizontalSpan=3;
gridData.heightHint=20;
tempComp.setLayoutData(gridData);
}
new Label(composite,SWT.READ_ONLY).setText("性 别:");
Combo sexCombo=new Combo(composite,SWT.NONE);
sexCombo.add("男");
sexCombo.add("女");
sexCombo.select(0);
new Label(composite,SWT.NONE).setText("姓名:");
Text nameText=new Text(composite,SWT.BORDER);
nameText.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
new Label(composite,SWT.NONE).setText("年龄:");
Text oldText=new Text(composite,SWT.BORDER);
oldText.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
new Label(composite,SWT.NONE).setText("毕业院校:");
Text schoolText=new Text(composite,SWT.BORDER);
schoolText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,3));
new Label(composite,SWT.READ_ONLY).setText("生肖:");
Combo animalCombo=new Combo(composite,SWT.BORDER);
animalCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
animalCombo.setItems(new String[]{"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"});
animalCombo.select(0);
new Label(composite,SWT.NONE).setText("职业:");
Text jobText=new Text(composite,SWT.BORDER);
jobText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,3));
new Label(composite,SWT.READ_ONLY).setText("星座:");
Combo constellationCombo=new Combo(composite,SWT.BORDER);
constellationCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
constellationCombo.setItems(new String[]{"白 羊 座","金 牛 座","双 子 座","巨 蟹 座","狮 子 座","处 女 座","天 秤 座","天 蝎 座","射 手 座","摩 羯 座","水 瓶 座","双 鱼 座"});
constellationCombo.select(0);
Label introLabel=new Label(composite,SWT.NONE);
introLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
introLabel.setText("个人说明:");
Text introText=new Text(composite,SWT.BORDER|SWT.WRAP);
introText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL|GridData.FILL_VERTICAL,5));
String yhhm=text.getText();
String yhnc=nicknameText.getText();
String gxqm=attachNameText.getText();
String xb=sexCombo.getItems().toString();
String xm=nameText.getText();
String nl=oldText.getText();
String sx=animalCombo.getItems().toString();
String byyx=schoolText.getText();
String zy=jobText.getText();
String grsm=introText.getText();
String xz=constellationCombo.getItems().toString();
return composite;
}
public static void main(String[] args) {
try
{
QQ window=new QQ();
window.open();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void open()
{
Display display = Display.getDefault();
Shell shell = new Shell();
shell.setSize(550, 350);
shell.setText("个人设计");
//
shell.setLayout(new GridLayout());
{
SashForm sashForm=new SashForm(shell,SWT.BORDER);
sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
{
selectList=new List(sashForm,SWT.BORDER);
selectList.setItems(new String[]{"个人资料","联系方式"});
selectList.addMouseListener(new MyMouseLister());
}
{
rightComp=new Composite(sashForm,SWT.NONE);
rightComp.setLayout(stackLayout);
yourDataComp=createYourDataComp(rightComp);
otherComp=createOtherComp(rightComp);
stackLayout.topControl = composite;
}
sashForm.setWeights(new int[]{1,4});
}
{
Composite buttonComp=new Composite(shell,SWT.BORDER);
GridData gridData=new GridData();
gridData.horizontalAlignment=GridData.END;
buttonComp.setLayoutData(gridData);
RowLayout rowLayout=new RowLayout();
rowLayout.spacing=15;
buttonComp.setLayout(rowLayout);
new Button(buttonComp,SWT.NONE).setText(" 确定 ");
new Button(buttonComp,SWT.NONE).setText(" 取消 ");
Button button1=new Button(buttonComp,SWT.NONE);
button1.setText(" 应用 ");
button1.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
//读取用户数据写入数据库
//数据库连接
DBControl dbc=new DBControl();
String insertSQL="INSERT INTO grxi(yhhm,yhnc,gxqm,xb,xm,nl,sx,byyx,zy,grsm,xz)VALUES("+"'"+yhhm+"','"+nicknameText.getText()+"','"+attachNameText.getText()+"','"+sexCombo.getItems()+"','"+nameText.getText()+"','"+oldText.getText()+"',"+animalCombo.getItems()+"','"+schoolText.getText()+"','"+jobText.getText()+"','"+introText.getText()+"','"+constellationCombo.getItems()+"')";
boolean suc1=false;
suc1=dbc.insertSQL(insertSQL);
if(suc1)
{
MessageDialog.openInformation((Shell) composite,null,"注册成功");
}
else{
MessageDialog.openInformation((Shell) composite,null,"注册失败");
}
}
});
}
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
private Composite createOtherComp(Composite rightComp){
composite=new Composite(rightComp,SWT.NONE);
composite.setLayout(new FillLayout());
new Label(composite,SWT.NONE).setText("联系方式面板");
return composite;
}
private GridData createGridData(int style,int horizontalSpan){
GridData gridData=new GridData(style);
gridData.horizontalSpan=horizontalSpan;
return gridData;
}
private GridData createGridData(int style,int horizontalSpan,int verticalSpan){
GridData gridData=new GridData(style);
gridData.horizontalSpan=horizontalSpan;
gridData.verticalSpan=verticalSpan;
return gridData;
}
private class MyMouseLister extends MouseAdapter{
public void mouseDown(MouseEvent e){
int selectionIndex=selectList.getSelectionIndex();
if(selectionIndex==0)
stackLayout.topControl=yourDataComp;
else
stackLayout.topControl=otherComp;
rightComp.layout();
}
};
}