SWT编写QQ个人资料界面 案例 例子

一款用于编辑QQ个人资料的应用程序,支持个性化签名、生日、星座等信息设置,并提供隐私权限管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*
 * @(#)QQPersonalSetWindows.java 1.0 09/03/26
 *
 * All rights reserved.
 */
package cn.edu.tsinghua.cs.keg.andy.swt;

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

/**
 * QQ个人资料输入器
 * @author Andy Wang
 * @version 1.0 09/03/26
 * @since JDK5.0
 */
public class QQPersonalSetWindows {
 
 private final String[] items = new String[]{"个人资料","联系方式"};
 private final String[] sexs = new String[]{"男","女"};
 private final String[] authoritys = new String[]{"完全公开","仅好友可见","完全保密"};
 private final String[] stars = new String[]{"","水瓶座","双鱼座","牡羊座","金牛座","双子座","巨蟹座","狮子座","处女座","天平座","天蝎座","射手座","摩羯座"};
 private final String[] shengxiaos = new String[]{"","鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"};
 private final String[] bloods = new String[]{"","A型","B型","O型","AB型","其它"};
 private final String[] months = new String[]{"","1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
 private final String[] days = new String[]{"","1日","2日","3日","4日","5日","6日","7日",
   "8日","9日","10日","11日","12日","13日","14日","15日","16日","17日","18日","19日",
   "20日","21日","22日","23日","24日","25日","26日","27日","28日","29日","30日","31日"};
 
 private String signTexts = "您还没有个性签名,赶快签名吧!!";
 
 private StackLayout stackLayout;
 private Composite rightPersonalCom;
 private Composite rightContactCom;
 private Composite rightCom;

 private QQPersonalSetWindows(){}
 
 /**
  *
  */
 public void open(){
  
  Display display = new Display();
  
  final Shell shell = new Shell(display,SWT.BORDER|SWT.CLOSE|SWT.MIN);
  shell.setSize(500, 420);
  shell.setText("QQ个人设置");
  shell.setToolTipText("我的资料--个人设置,请填写内容!");
  GridLayout gridLayout = new GridLayout();
  shell.setLayout(gridLayout);
  {
//          分割窗口为左,右两部分
   SashForm sashForm = new SashForm(shell,SWT.NONE);
   
   GridData gridData = new GridData(GridData.FILL_BOTH);
   sashForm.setLayoutData(gridData);
   {
//    分割左边的列表框
    List selectList = new List(sashForm,SWT.BORDER);
    selectList.setItems(items);
    selectList.addMouseListener(new MyMouseListener(selectList));
   }
   {
//    右边堆栈式面板
    stackLayout = new StackLayout();
    rightCom = new Composite(sashForm,SWT.BORDER);
    rightCom.setLayout(stackLayout);
    rightPersonalCom = this.createPersonalMsg(rightCom);
    rightContactCom = this.createContact(rightCom);
    
//    设置初始化显示的面板
    stackLayout.topControl = rightPersonalCom;
    
   }
   sashForm.setWeights(new int[]{1,3});
//   sashForm.setBounds(20, 20, 500, 420);
  }
  {
//   按钮面板
   Composite buttonComp = new Composite(shell,SWT.NONE);
   GridData btnGridData = new GridData();
   btnGridData.horizontalAlignment = GridData.END;
   buttonComp.setLayoutData(btnGridData);
   RowLayout btnRL = new RowLayout();
   btnRL.spacing = 20;
   buttonComp.setLayout(btnRL);
   
   Button enterBtn = new Button(buttonComp,SWT.NONE);
   enterBtn.setText("   确定    ");
   
   Button cancleBtn = new Button(buttonComp,SWT.NONE);
   cancleBtn.setText("   取消   ");
   
   Button appBtn = new Button(buttonComp,SWT.NONE);
   appBtn.setText("   应用   ");
  }
  
  shell.layout();
  shell.open();
  while(!shell.isDisposed()){
   if(!display.readAndDispatch()){
    display.sleep();
   }
  }
  display.dispose();
 }
 
 /**
  * 个人资料面板
  * @param composite
  * @return
  */
 private Composite createPersonalMsg(Composite rightComposite){
   Composite composite = new Composite(rightComposite,SWT.BORDER);
   composite.setLayout(new GridLayout(10,false));//面板采用GridLayout布局管理器,分成六列
   Label nickName = new Label(composite,SWT.NONE);
   nickName.setText("昵称:");
   nickName.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,5));
  
   Label qqNum = new Label(composite,SWT.NONE);
   qqNum.setText("账号:(绑定邮箱账号)");
   qqNum.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,5));
  
   Text nickText = new Text(composite,SWT.BORDER);
   nickText.setText("baby_nanhai");
   nickText.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,5));
  
   Text numText = new Text(composite,SWT.BORDER);
   numText.setText("545073934");
   numText.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,5));  

   Label grade = new Label(composite,SWT.NONE);
   grade.setText("等级:");
   grade.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL,1));
  
   Text gradeText = new Text(composite,SWT.BORDER);
   gradeText.setText("这里设置Image图标");
   gradeText.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL,9));
  
   Label sign = new Label(composite,SWT.NONE);
   sign.setText("个性签名:");
   sign.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL,10));
  
   Text signText = new Text(composite,SWT.BORDER|SWT.WRAP);
   signText.setText(signTexts);
   signText.setLayoutData(this.createGridData4(GridData.HORIZONTAL_ALIGN_FILL,50,10));
  
   Label sex = new Label(composite,SWT.NONE);
   sex.setText("性别:");
   sex.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,2));
  
   Label age = new Label(composite,SWT.NONE);
   age.setText("年龄:");
   age.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,1));
  
   Label birth = new Label(composite,SWT.NONE);
   birth.setText("生日:");
   birth.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL,7));
  
   Combo sexCombo = new Combo(composite,SWT.NONE);
   sexCombo.setItems(sexs);
   sexCombo.select(0);
   sexCombo.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,2));
  
   Text ageText = new Text(composite,SWT.BORDER);
   ageText.setText("0");
   ageText.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,1));
  
   Combo birtMonthsCombo = new Combo(composite,SWT.NONE);
   birtMonthsCombo.setItems(months);
   birtMonthsCombo.select(0);
   birtMonthsCombo.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL,3));
  
   Combo birtDaysCombo = new Combo(composite,SWT.NONE);
   birtDaysCombo.setItems(days);
   birtDaysCombo.select(0);
   birtDaysCombo.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL,3));
   birtDaysCombo.setEnabled(false);
  
   Label shengxiao = new Label(composite,SWT.NONE);
   shengxiao.setText("生肖:");
   shengxiao.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,2));
  
   Label blood = new Label(composite,SWT.NONE);
   blood.setText("血型:");
   blood.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,1));
  
   Label starSign = new Label(composite,SWT.NONE);
   starSign.setText("星座:");
   starSign.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL,7));
  
   Combo shengxiaoCombo = new Combo(composite,SWT.NONE);
   shengxiaoCombo.setItems(shengxiaos);
   shengxiaoCombo.select(0);
   shengxiaoCombo.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,2));
  
   Combo bloodCombo = new Combo(composite,SWT.NONE);
   bloodCombo.setItems(bloods);
   bloodCombo.select(0);
   bloodCombo.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,1));
  
   Combo starCombo = new Combo(composite,SWT.NONE);
   starCombo.setItems(stars);
   starCombo.select(0);
   starCombo.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL,7));

  
  
  
  return composite;
 }
 
 /**
  * 更多资料面板编辑器
  * @param rightComposite
  * @return
  */
 private Composite createContact(Composite rightComposite){
  Composite composite = new Composite(rightComposite,SWT.BORDER);
  composite.setLayout(new GridLayout(2,false));
  
  final Label authority = new Label(composite,SWT.NONE);
  authority.setText("请选择以下资料的显示范围:");
  authority.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL, 1));
  
  final Label mobile = new Label(composite,SWT.NONE);
  mobile.setText("手机:");
  mobile.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL, 1));
  
  Combo authorityCombo = new Combo(composite,SWT.NONE);
  authorityCombo.setItems(authoritys);
  authorityCombo.select(2);
  authorityCombo.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL,1));
  
  final Text mobileText = new Text(composite,SWT.BORDER);
  mobileText.setText("-");
  mobileText.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,1));
  
  final Label telephone = new Label(composite,SWT.NONE);
  telephone.setText("电话:");
  telephone.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL, 1));
  
  final Label email = new Label(composite,SWT.NONE);
  email.setText("邮箱:");
  email.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL, 1));
  
  final Text telephoneText = new Text(composite,SWT.BORDER);
  telephoneText.setText("-");
  telephoneText.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL,1));
  
  final Text emailText = new Text(composite,SWT.BORDER);
  emailText.setText("-");
  emailText.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,1));
  
  final Label job = new Label(composite,SWT.NONE);
  job.setText("职业:");
  job.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL, 1));
  
  final Label college = new Label(composite,SWT.NONE);
  college.setText("毕业院校:");
  college.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL, 1));
  
  final Text jobText = new Text(composite,SWT.BORDER);
  jobText.setText("-");
  jobText.setLayoutData(this.createGridData2(GridData.HORIZONTAL_ALIGN_FILL,1));
  
  final Text collegeText = new Text(composite,SWT.BORDER);
  collegeText.setText("-");
  collegeText.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,1));
  
  final Label page = new Label(composite,SWT.NONE);
  page.setText("个人主页:");
  page.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL, 2));
  
  final Text pageText = new Text(composite,SWT.BORDER);
  pageText.setText("-");
  pageText.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL,2));
  
  final Label introduce = new Label(composite,SWT.NONE);
  introduce.setText("个人说明:");
  introduce.setLayoutData(this.createGridData2(GridData.FILL_HORIZONTAL, 2));
  
  final Text introduceText = new Text(composite,SWT.BORDER);
  introduceText.setText("-");
  introduceText.setLayoutData(this.createGridData4(GridData.FILL_HORIZONTAL,70,2));
  
  return composite;
 }
 
 /**
  *
  * @param horizontalSpan
  * @return
  */
 private GridData createGridData1(int horizontalSpan){
  GridData gridData = new GridData();
  gridData.horizontalSpan = horizontalSpan;
//  gridData.verticalSpan = verticalSpan;
  return gridData;
 }
 
 /**
  * 创建GridData
  * @param stytle 风格
  * @param horizontalSpan 合并列数
  * @return
  */
 private GridData createGridData2(int stytle,int horizontalSpan){
  GridData gridData = new GridData(stytle);
  gridData.horizontalSpan = horizontalSpan;
//  gridData.horizontalAlignment = GridData.CENTER;
  return gridData;
 }
 
 /**
  * 创建GridData
  * @param stytle 风格
  * @param horizontalSpan 合并列数
  * @param verticalSpan 合并行数
  * @return
  */
 private GridData createGridData3(int stytle,int horizontalSpan,int verticalSpan){
  GridData gridData = new GridData(stytle);
  gridData.horizontalSpan = horizontalSpan;
  gridData.verticalSpan = verticalSpan;
  
  return gridData;
 }
 
 /**
  *
  * @param stytle
  * @param heightHint
  * @param horizontalSpan
  * @return
  */
 private GridData createGridData4(int stytle,int heightHint,int horizontalSpan){
  GridData gridData = new GridData(stytle);
  gridData.heightHint = heightHint;
  gridData.horizontalSpan = horizontalSpan;
  return gridData;
 }
 
 /**
  * 鼠标单击事件
  * @author Andy Wang
  *
  */
 private final class MyMouseListener extends MouseAdapter{

  private List list;
  public MyMouseListener(){}
  public MyMouseListener(List list){
   this.list = list;
  }
  
  public void mouseDown(MouseEvent e) {
   int selectIndex = list.getSelectionIndex();
   if(selectIndex == 0){
    stackLayout.topControl = rightPersonalCom;
    rightCom.layout();
   }else{
    stackLayout.topControl = rightContactCom;
    rightCom.layout();
   }
  }  
 }
 
 /**
  * main start QQ
  * @param args
  */
 public static void main(String[] args){
  try {
   QQPersonalSetWindows qq = new QQPersonalSetWindows();
   qq.open();
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值