类似于QQ用户信息的界面


package com.swtdesigner;

import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;

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.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;

public class QQ
{

  private StackLayout stackLayout;
  private Composite yourDataComp;
  private Composite otherComp;
  private List selectList;
  private Composite rightComp;
  
  

  /**
   * Launch the application
   * @param args
   */
  public static void main(String[] args) {
    try {
      QQ window = new QQ();
      window.open();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  /**
   * Open the window
   */
  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 MyMouseListener());
  }
{//分割栏右边的窗口
rightComp=new Composite(sashForm,SWT.NONE);
   rightComp.setLayout(stackLayout);
  
yourDataComp=createYourDataComp(rightComp);//建立个人资料面板
otherComp=createOtherComp(rightComp);//建立连续方式面板
stackLayout.topControl=otherComp;
//rightComp.layout();
      }
  //左右空间比
      
  sashForm.setWeights(new int[]{1,4});
    
    }
  {//界面的按钮面板
  Composite buttonComp=new Composite(shell,SWT.BORDER);
  GridData gridData=new GridData();
  gridData.horizontalAlignment=GridData.END;
   buttonComp.setLayoutData(gridData);//让button向右靠
      
   RowLayout rowLayout=new RowLayout();
   rowLayout.spacing=15;//按钮间距15象素
   buttonComp.setLayout(rowLayout);
   //新建三个按钮
   new Button(buttonComp,SWT.NONE).setText(" 确定 ");
   new Button(buttonComp,SWT.NONE).setText(" 取消 ");
   new Button(buttonComp,SWT.NONE).setText(" 应用 ");
  }
    
    
    
  createContents();
  shell.layout();
  shell.open();
    
  while (!shell.isDisposed()) {
  if (!display.readAndDispatch())
  display.sleep();
    }
  }
  private Composite createYourDataComp(Composite rightComp)
  {
  Composite composite =new Composite(rightComp,SWT.NONE);
  composite.setLayout(new GridLayout(6,false));//分成6列
  new Label(composite,SWT.NONE).setText("用户号码:");
  Text text=new Text(composite,SWT.READ_ONLY/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));
    {
      //pic
  Composite tempComp=new Composite(photoComp,SWT.BORDER);
  tempComp.setLayoutData(new GridData(50,50));
      
  Button setPhotoButton=new Button(photoComp,SWT.ARROW|SWT.DOWN);
  setPhotoButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));
      
  Button updateButton=new Button(photoComp,SWT.NONE);
  updateButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL,2));
   updateButton.setText("升级为会员");
      
      
    }
    
  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.BEGINNING);
  gridData.horizontalSpan=3;
  gridData.heightHint=20;
  tempComp.setLayoutData(gridData);
     }
    
   new Label(composite,SWT.NONE).setText("性 别:");
Combo sexCombo=new Combo(composite,SWT.NONE);    

new Label(composite,SWT.NONE).setText("姓名:");
  Text nameText=new Text(composite,SWT.BORDER);
  nameText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL));
      
  new Label(composite,SWT.NONE).setText("年龄:");
  Text oldText=new Text(composite,SWT.BORDER);
  oldText.setLayoutData(createGridData(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.NONE).setText("生肖:");
  Text animalText=new Text(composite,SWT.NONE);
  animalText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL));
  new Label(composite,SWT.NONE).setText("职业:");
  Text careerText=new Text(composite,SWT.BORDER);
  careerText.setLayoutData(createGridData(GridData.HORIZONTAL_ALIGN_FILL,3));
  new Label(composite,SWT.NONE).setText("星座:");
  Combo constellationCombo=new Combo(composite,SWT.NONE);
  constellationCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
      
  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));
      return composite;
     }
  
  private Composite createOtherComp(Composite rightComp)
  {
    Composite composite =new Composite(rightComp,SWT.BORDER);
    composite.setLayout(new FillLayout());
    //new Label(composite,SWT.NONE).setText("联系方式面板");
    return composite;
  }
  

    private GridData createGridData(int style)
    {
      GridData gridData=new GridData(style);
      return gridData;
    }
    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 MyMouseListener extends MouseAdapter
    {
    public void mouseDown(MouseEvent e)
      {
        int selectionIndex=selectList.getSelectionIndex();
        if(selectionIndex==0)
          stackLayout.topControl=yourDataComp;
        else
          stackLayout.topControl=otherComp;
         rightComp.layout();
       }    
     }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值