import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.SWT;
public class e {
public static void main(String[] arg){
final Display display=new Display();
final Shell shell1=new Shell(display);
shell1.setText("  ");
 final Text text1=new Text(shell1,SWT.BORDER);
    text1.setBounds(150, 100, 150, 25);
    final Text text2=new Text(shell1,SWT.BORDER);
    text2.setBounds(150, 150, 150, 25);
    Button bt1=new Button(shell1,SWT.NONE);
    bt1.setText("管理员");
    bt1.setBounds(100, 220, 60, 25);
    bt1.addSelectionListener(new SelectionAdapter(){
    
     public void widgetSelected(SelectionEvent e){
      
      if(text1.equals("admin") && text2.equals("admin")){
      
       Shell shell5=new Shell(display);
    shell5.setText("注册");
    shell5.setBounds(200, 200, 400, 400);
    Label lb11=new Label(shell5,SWT.NONE);
    lb11.setText("用户名");
    lb11.setBounds(50, 55,100 ,25 );
    shell5.open();
      }
     
}
});
    shell1.open();
    while (!shell1.isDisposed()){
     if(!display.readAndDispatch()){
    
     display.sleep();
     }
    }
display.dispose();
    }
}
如果去掉if语句就可以了   这是怎么回事儿    求请教

解决方案 »

  1.   

    哦  我解釋下   就是button按钮按了以后text里面的内容符合字符串“admin”就可以跳转到另外一个界面去了
    所以加了if语句判断是不是符合要求    
    现在的问题就是text的字符串符合要求了  但不能到另外一个界面。如果去掉if语句不判定的话就可以了,就是不知道哪里写错了。
      

  2.   

    你 Text text2的类型是Text 怎么能和字符串比较大小呢,你应该获取内容去比较啊
      

  3.   

    if(text1.equals("admin") && text2.equals("admin")){改成if(text1.getText().equals("admin") && text2.getText().equals("admin")){试试