首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

新手有关问题 纠结ing

2013-03-19 
新手问题纠结ingimport org.eclipse.swt.widgets.*import org.eclipse.swt.events.*import org.eclipse.

新手问题 纠结ing
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语句就可以了   这是怎么回事儿    求请教
[解决办法]
你 Text text2的类型是Text 怎么能和字符串比较大小呢,你应该获取内容去比较啊
[解决办法]
if(text1.equals("admin") && text2.equals("admin")){改成if(text1.getText().equals("admin") && text2.getText().equals("admin")){试试

热点排行