Topic: 请问问题是我的程序还是配置的有问题??? |
Print this page |
1.请问问题是我的程序还是配置的有问题??? | Copy to clipboard |
Posted by: foster_shao Posted on: 2006-05-30 22:49 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(); } } } |
2.Re:请问问题是我的程序还是配置的有问题??? [Re: foster_shao] | Copy to clipboard |
Posted by: lisliefor Posted on: 2006-05-31 12:38 最害怕一贴,贴一大版程序,而对错误已经修改错误的过程只言片语地带过! 汗一个...... 勉强下定决心帮你调试,却发现你improt的那些包,我都没有。 所以...... |
3.Re:请问问题是我的程序还是配置的有问题??? [Re: foster_shao] | Copy to clipboard |
Posted by: foster_shao Posted on: 2006-06-06 21:46 java.lang.NullPointerException 出现这种错误的原因有没有清楚的呢? 附件中有SWT包,我用eclipse+附件中SWT包 调试出以上错误, 删stackLayout.topControl=otherComp; 这一句就ok,可以运行, 但不是我要的效果 |
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 |