Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 实战错误讨论  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 请问问题是我的程序还是配置的有问题???
foster_shao





发贴: 6
积分: 0
于 2006-05-30 22:49 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
java.lang.NullPointerException
  at com.swtdesigner.QQ.open(QQ.java:68)
  at com.swtdesigner.QQ.main(QQ.java:36)
用Eclipse的SWT designer 写一个类似于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();
       }    
     }
}




关于Jute Forum的长期发展给官方的建议

话题树型展开
人气 标题 作者 字数 发贴时间
5902 请问问题是我的程序还是配置的有问题??? foster_shao 6906 2006-05-30 22:49
4608 Re:请问问题是我的程序还是配置的有问题??? lisliefor 93 2006-05-31 12:38
5160 Re:请问问题是我的程序还是配置的有问题??? foster_shao 155 2006-06-06 21:46

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923