快速业务通道

了解Eclipse中的JFace数据绑定,第2部分: 绑定的基础知识 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-19
击按钮时这些值已与 Person Bean 手动同步。

此示例的代码如下所示。

清单 1. 具有手动同步功能的示例应用程序

public class Person {   private String first;   private String last;   public Person(String first, String last) {   this.first = first;   this.last = last;   }   public String getFirst() {   return first;   }   public void setFirst(String first) {   this.first = first;   }   public String getLast() {   return last;   }   public void setLast(String last) {   this.last = last;   } } public class NoBindingExample {   private Person person;   private Text firstText;   private Text lastText;   private void createControls(Shell shell) {   GridLayout gridLayout = new GridLayout();   gridLayout.numColumns = 2;   shell.setLayout(gridLayout);   Label label = new Label(shell, SWT.SHELL_TRIM);   label.setText("First:");   GridData gridData = new GridData(GridData.FILL_HORIZONTAL);   this.firstText = new Text(shell, SWT.BORDER);   this.firstText.setLayoutData(gridData);   label = new Label(shell, SWT.NONE);   label.setText("Last:");   this.lastText = new Text(shell, SWT.BORDER);   gridData = new GridData(GridData.FILL_HORIZONTAL);   this.lastText.setLayoutData(gridData);   }   private void createButtons(Shell shell) {   GridData gridData;   gridData = new GridData();   gridData.horizontalAlignment = SWT.CENTER;   gridData.horizontalSpan = 2;   Button button = new Button(shell, SWT.PUSH);   button.setLayoutData(gridData);   button.setText("Change Name");   button.addSelectionListener(new SelectionAdapter() {    public void widgetSelected(SelectionEvent e) {    updatePerson();    synchronizePersonToUI();    }   });   gridData = new GridData();   gridData.horizontalAlignment = SWT.CENTER;   gridData.horizontalSpan = 2;   button = new Button(shell, SWT.PUSH);   button.setLayoutData(gridData);   button.setText("Update Person Bean From Text");   button.addSelectionListener(new SelectionAdapter() {    public void widgetSelected(SelectionEvent e) {    synchronizeUIToPerson();    }   });   gridData = new GridData();   gridData.horizontalAlignment = SWT.CENTER;   gridData.horizontalSpan = 2;   button = new Button(shell, SWT.PUSH);   button.setLayoutData(gridData);   button.setText("Update Text From Person Bean");   button.addSelectionListener(new SelectionAdapter() {    public void widgetSelected(SelectionEvent e) {    synchronizePersonToUI();    }   });   }   private void updatePerson() {   person.setFirst("James");   person.setLast("Gosling");   }   private void synchronizePersonToUI() {   this.firstText.setText(this.person.getFirst());   this.lastText.setText(this.person.getLast());   }   private void synchronizeUIToPerson() {   th

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号