www.pudn.com > SwtDemo.rar > SwtDemo.java


/* 
 * Created on 2004-10-16 
 * 
 * TODO To change the template for this generated file go to 
 * Window - Preferences - Java - Code Style - Code Templates 
 */ 
package src; 
import src.HsqlSimpleApp; 
import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.Shell; 
import org.eclipse.swt.SWT; 
import org.eclipse.swt.widgets.Button; 
import com.swtdesigner.ResourceManager; 
import org.eclipse.swt.widgets.Group; 
import org.eclipse.swt.events.SelectionAdapter; 
import org.eclipse.swt.events.SelectionEvent; 
import org.eclipse.swt.widgets.Text; 
import org.eclipse.swt.widgets.Label; 
 
/** 
 * @author lqm 
 * 
 * TODO To change the template for this generated type comment go to 
 * Window - Preferences - Java - Code Style - Code Templates 
 */ 
public class SwtDemo { 
 
	protected Shell shell; 
 
	public static void main(String[] args) { 
		SwtDemo window = new SwtDemo(); 
		window.open(); 
	} 
 
	public void open() { 
		final Display display = Display.getDefault(); 
		createContents(); 
		shell.layout(); 
		shell.open(); 
		while (!shell.isDisposed()) { 
			if (!display.readAndDispatch()) 
				display.sleep(); 
		} 
	} 
 
	protected void createContents() { 
		shell = new Shell(); 
		shell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); 
		shell.setSize(317, 172); 
		shell.setText("用户登录"); 
 
 
 
		final Button delete = new Button(shell, SWT.NONE); 
		delete.addSelectionListener(new SelectionAdapter() { 
			public void widgetSelected(SelectionEvent e) { 
			} 
		}); 
		delete.setFont(ResourceManager.getFont("", 12, SWT.BOLD | SWT.ITALIC)); 
		delete.setBounds(195, 100, 70, 30); 
		delete.setText("delete"); 
 
		final Group group = new Group(shell, SWT.NONE); 
		group.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); 
		group.setBounds(25, 0, 260, 95); 
 
		final Text userid = new Text(group, SWT.BORDER); 
		userid.setBounds(115, 16, 100, 25); 
		 
 
		final Text username = new Text(group, SWT.BORDER); 
		username.setBounds(115, 54, 100, 25); 
		 
		final Button query = new Button(shell, SWT.NONE); 
		query.addSelectionListener(new SelectionAdapter() { 
			public void widgetSelected(SelectionEvent e) { 
				HsqlSimpleApp hsq = new HsqlSimpleApp(); 
				String userID= userid.getText().toString();  //需要转换成字符串 
				String userName= username.getText().toString(); 
				hsq.go(userID,userName); 
				 
			} 
		}); 
		query.setFont(ResourceManager.getFont("@仿宋_GB2312", 12, SWT.BOLD | SWT.ITALIC)); 
		query.setBounds(40, 100, 75, 30); 
		query.setText("query"); 
 
		final Label label = new Label(group, SWT.NONE); 
		label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); 
		label.setFont(ResourceManager.getFont("", 12, SWT.BOLD | SWT.ITALIC)); 
		label.setBounds(35, 18, 80, 25); 
		label.setText("用户号:"); 
 
		final Label label_1 = new Label(group, SWT.NONE); 
		label_1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); 
		label_1.setFont(ResourceManager.getFont("", 12, SWT.BOLD | SWT.ITALIC)); 
		label_1.setBounds(40, 55, 55, 25); 
		label_1.setText("姓名:"); 
	} 
	 
 
 
}