关闭

类似于QQ用户信息的界面

875人阅读 评论(0) 收藏 举报

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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:10224次
    • 积分:166
    • 等级:
    • 排名:千里之外
    • 原创:7篇
    • 转载:1篇
    • 译文:0篇
    • 评论:2条
    文章存档
    阅读排行
    最新评论
  • SWT(2)

    MangDong: 不知CSDN的评论发布系统对于评论大小有多少限制,我发的评论竟然只有开头部分,唉真是遗憾。算了。我发...

  • SWT(2)

    MangDong: SWT程序的组件构造惯用法跟Swing程序很不一样。Swing程序是第一次使用构造法,跟单态模式很想...