在一个登录界面中设置了注册按钮,想在点击注册按钮的同时弹出一个新的注册页面,可是出现了线程的错误:
Exception in thread "main" org.eclipse.swt.SWTException: Invalid thread access
求高手解答,感谢!
这个是登录界面中注册按钮的设置:
Button registerButton = new Button(buttonComp,SWT.NONE|SWT.CENTER); //注册按钮
registerButton.setText(" 注册 ");
registerButton.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e)
{
new newUser();
}
});
这个是新的注册界面的代码:
package cn.chenxiang.Interface;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class newUser
{
public newUser()
{
Display display = new Display();
FillLayout fillLayout = new FillLayout();
Shell shell = new Shell(SWT.CLOSE|SWT.MIN|SWT.TITLE);
shell.setText("期刊管理系统");
shell.setBounds(200,250,300,210);
shell.setLayout(fillLayout);
Composite comp = new Composite(shell,SWT.NONE);
GridLayout gridLayout = new GridLayout(2,false);
gridLayout.verticalSpacing = 10 ;
gridLayout.marginTop = 5 ;
gridLayout.marginRight = 10 ;
comp.setLayout(gridLayout);
comp.setToolTipText("读者信息注册");
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.grabExcessHorizontalSpace = true ;
GridData gridDataT = new GridData(GridData.FILL_HORIZONTAL);
Label label1 = new Label(comp,SWT.NONE|SWT.CENTER);
label1.setText("读者姓名:");
label1.setLayoutData(gridData);
Text text1 = new Text(comp,SWT.NONE|SWT.BORDER);
text1.setLayoutData(gridDataT);
Label label2 = new Label(comp,SWT.NONE|SWT.CENTER);
label2.setText("年龄:");
label2.setLayoutData(gridData);
Text text2 = new Text(comp,SWT.NONE|SWT.BORDER);
text2.setLayoutData(gridDataT);
Label label3 = new Label(comp,SWT.NONE|SWT.CENTER);
label3.setText("性别:");
label3.setLayoutData(gridData);
Text text3 = new Text(comp,SWT.NONE|SWT.BORDER);
text3.setLayoutData(gridDataT);
Label label4 = new Label(comp,SWT.NONE|SWT.CENTER);
label4.setText("TEL:");
label4.setLayoutData(gridData);
Text text4 = new Text(comp,SWT.NONE|SWT.BORDER);
text4.setLayoutData(gridDataT);
Label label5 = new Label(comp,SWT.NONE|SWT.CENTER);
label5.setText("E-mail:");
label5.setLayoutData(gridData);
Text text5 = new Text(comp,SWT.NONE|SWT.BORDER);
text5.setLayoutData(gridDataT);
GridData gridB1 = new GridData();
gridB1.horizontalAlignment = GridData.END;
Button button1 = new Button(comp,SWT.NONE|SWT.ARROW_LEFT);
button1.setText(" 注册 ");
button1.setLayoutData(gridB1);
Button button2 = new Button(comp,SWT.NONE);
button2.setText(" 取消 ");
shell.open();
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args)
{
new newUser();
}
}