java swt button_SWT Button 事件例子

packagecom.wy;importorg.eclipse.swt.SWT;importorg.eclipse.swt.events.SelectionAdapter;importorg.eclipse.swt.events.SelectionEvent;importorg.eclipse.swt.layout.grouplayout.GroupLayout;importorg.eclipse.swt.layout.grouplayout.LayoutStyle;importorg.eclipse.swt.widgets.Button;importorg.eclipse.swt.widgets.Display;importorg.eclipse.swt.widgets.Label;importorg.eclipse.swt.widgets.Shell;importorg.eclipse.swt.widgets.Text;publicclasstestForm001 {privateText txtName;privateButton btnMyPress;protectedShell shell;/*** Launch the application

*@paramargs*/publicstaticvoidmain(String[] args) {try{

testForm001 window=newtestForm001();

window.open();

}catch(Exception e) {

e.printStackTrace();

}

}/*** Open the window*/publicvoidopen() {finalDisplay display=Display.getDefault();

createContents();newtestEvent001(this);

shell.open();

shell.layout();while(!shell.isDisposed()) {if(!display.readAndDispatch())

display.sleep();

}

}publicText gettxtName()

{returntxtName;

}publicButton getbtnMyPress()

{returnbtnMyPress;

}/*** Create contents of the window*/protectedvoidcreateContents() {

shell=newShell();

shell.setText("SWT Application");

btnMyPress=newButton(shell, SWT.NONE);

btnMyPress.setData("newKey",null);

btnMyPress.setText("buttonbtnMyPressvalue");

Label lblMsg;

lblMsg=newLabel(shell, SWT.NONE);

lblMsg.setText("Labelvalue");

txtName=newText(shell, SWT.BORDER);

txtName.setRedraw(true);finalGroupLayout groupLayout=newGroupLayout(shell);

groupLayout.setHorizontalGroup(

groupLayout.createParallelGroup(GroupLayout.LEADING)

.add(groupLayout.createSequentialGroup()

.add(groupLayout.createParallelGroup(GroupLayout.LEADING)

.add(groupLayout.createSequentialGroup()

.add(35,35,35)

.add(lblMsg, GroupLayout.PREFERRED_SIZE,111, GroupLayout.PREFERRED_SIZE))

.add(groupLayout.createSequentialGroup()

.add(78,78,78)

.add(btnMyPress, GroupLayout.PREFERRED_SIZE,151, GroupLayout.PREFERRED_SIZE))

.add(groupLayout.createSequentialGroup()

.add(3,3,3)

.add(txtName, GroupLayout.PREFERRED_SIZE,217, GroupLayout.PREFERRED_SIZE)))

.addContainerGap(263, Short.MAX_VALUE))

);

groupLayout.setVerticalGroup(

groupLayout.createParallelGroup(GroupLayout.LEADING)

.add(groupLayout.createSequentialGroup()

.add(45,45,45)

.add(lblMsg, GroupLayout.PREFERRED_SIZE,44, GroupLayout.PREFERRED_SIZE)

.add(29,29,29)

.add(btnMyPress, GroupLayout.PREFERRED_SIZE,61, GroupLayout.PREFERRED_SIZE)

.add(27,27,27)

.add(txtName, GroupLayout.PREFERRED_SIZE,80, GroupLayout.PREFERRED_SIZE)

.add(55,55,55))

);

shell.setLayout(groupLayout);

shell.pack();//}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值