62,623
社区成员
发帖
与我相关
我的任务
分享
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
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 LoginDemo extends Shell
{
private Text txtPsd;
private Text txtUser;
/**
* Launch the application
* @param args
*/
public static void main(String args[])
{
try
{
Display display = Display.getDefault();
LoginDemo shell = new LoginDemo(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
catch(Exception e)
{
e.printStackTrace();
}
}
/**
* Create the shell
* @param display
* @param style
*/
public LoginDemo(Display display, int style)
{
super(display, style);
createContents();
}
/**
* Create contents of the window
*/
protected void createContents()
{
setText("SWT Application");
setSize(416, 279);
final Label lbUser = new Label(this, SWT.NONE);
lbUser.setText("用户名");
lbUser.setBounds(45, 80, 52, 21);
final Label lbPsd = new Label(this, SWT.NONE);
lbPsd.setText("密 码");
lbPsd.setBounds(45, 120, 52, 21);
txtUser = new Text(this, SWT.BORDER);
txtUser.setBounds(103, 75, 260, 25);
txtPsd = new Text(this, SWT.BORDER);
txtPsd.setEchoChar('*');
txtPsd.setBounds(103, 113, 260, 25);
final Button btnLogin = new Button(this, SWT.NONE);
btnLogin.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(final SelectionEvent e)
{
}
});
btnLogin.setText("登陆");
btnLogin.setBounds(80, 191, 84, 25);
final Button btnClear = new Button(this, SWT.NONE);
btnClear.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(final SelectionEvent e)
{
}
});
btnClear.setText("清空");
btnClear.setBounds(244, 191, 84, 25);
//
}
@Override
protected void checkSubclass()
{
// Disable the check that prevents subclassing of SWT components
}
}