JGoodies数据绑定:提供组件范例2 : 数据绑定 « Swing组件 « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » Swing组件 » 数据绑定屏幕截图 
JGoodies数据绑定:提供组件范例2
JGoodies数据绑定:提供组件范例2

/*
Code revised from Desktop Java Live:
http://www.sourcebeat.com/downloads/
*/
import java.awt.event.ActionEvent;
import java.util.Arrays;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;

public class FeedBeanExample2 extends JPanel {
    JTextField nameField;
    JTextField siteField;
    JTextField feedField;
    JComboBox feedTypesComboBox;
    JCheckBox customCheckIntervalCheckbox;
    JTextField intervalField;

    Feed feed;

    public FeedBeanExample2() {
        DefaultFormBuilder formBuilder = new DefaultFormBuilder(new FormLayout(""));
        formBuilder.setBorder(BorderFactory.createEmptyBorder(5555));
        formBuilder.appendColumn("right:pref");
        formBuilder.appendColumn("3dlu");
        formBuilder.appendColumn("fill:p:g");

        this.nameField = new JTextField();
        formBuilder.append("Name:"this.nameField);
        this.siteField = new JTextField();
        formBuilder.append("Site Url:"this.siteField);
        this.feedField = new JTextField();
        formBuilder.append("Feed Url:"this.feedField);
        this.feedTypesComboBox = new JComboBox(Arrays.asList(new FeedType[]{
                new FeedType("RSS_09")new FeedType("RSS_093")new FeedType("RSS_20")
        new FeedType("ATOM_03")}).toArray());
        formBuilder.append("Feed Type:"this.feedTypesComboBox);
        this.customCheckIntervalCheckbox = new JCheckBox();
        formBuilder.append("Custom Check Interval:"this.customCheckIntervalCheckbox);
        this.intervalField = new JTextField();
        formBuilder.append("Interval:"this.intervalField);

        formBuilder.append(new JButton(new ShowFeedInformationAction())3);


        createFeed();
        initializeFormElements();

        add(formBuilder.getPanel());
    }

    private void createFeed() {
        this.feed = new Feed();
        this.feed.setName("ClientJava.com");
        this.feed.setSiteUrl("http://www.clientjava.com/blog");
        this.feed.setFeedUrl("http://www.clientjava.com/blog/rss.xml");
        this.feed.setFeedType(new FeedType("RSS_20"));
        this.feed.setCustomCheckIntervalEnabled(true);
        this.feed.setCheckInterval(new Integer(4));
    }

    private void initializeFormElements() {
        this.nameField.setText(this.feed.getName());
        this.siteField.setText(this.feed.getSiteUrl());
        this.feedField.setText(this.feed.getFeedUrl());

        this.feedTypesComboBox.setSelectedItem(this.feed.getFeedType());
        this.customCheckIntervalCheckbox.setSelected(this.feed.isCustomCheckIntervalEnabled());

        if (this.feed.getCheckInterval() != null) {
            this.intervalField.setText(this.feed.getCheckInterval().toString());
        }
    }

    private void synchFormAndFeed() {
        this.feed.setName(this.nameField.getText());
        this.feed.setSiteUrl(this.siteField.getText());
        this.feed.setFeedUrl(this.feedField.getText());
        this.feed.setFeedType((FeedTypethis.feedTypesComboBox.getSelectedItem());
        this.feed.setCustomCheckIntervalEnabled(this.customCheckIntervalCheckbox.isSelected());
        if (this.feed.isCustomCheckIntervalEnabled()) {
            this.feed.setCheckInterval(new Integer(this.intervalField.getText()));
        else {
            this.feed.setCheckInterval(null);
        }
    }

    private Feed getFeed() {
        return this.feed;
    }

    private class ShowFeedInformationAction extends AbstractAction {
        public ShowFeedInformationAction() {
            super("Show Feed Information");
        }

        public void actionPerformed(ActionEvent event) {
            synchFormAndFeed();

            StringBuffer message = new StringBuffer();
            message.append("<html>");
            message.append("<b>Name:</b> ");
            message.append(getFeed().getName());
            message.append("<br>");
            message.append("<b>Site URL:</b> ");
            message.append(getFeed().getSiteUrl());
            message.append("<br>");
            message.append("<b>Feed URL:</b> ");
            message.append(getFeed().getFeedUrl());
            message.append("<br>");
            message.append("<b>Feed Type:</b> ");
            message.append(getFeed().getFeedType());
            message.append("<br>");
            message.append("<b>Custom Check:</b> ");
            message.append(getFeed().isCustomCheckIntervalEnabled());
            message.append("<br>");
            message.append("<b>Check Interval:</b> ");
            message.append(getFeed().getCheckInterval());
            message.append("</html>");

            JOptionPane.showMessageDialog(null, message.toString());
        }
    }

    public static void main(String[] a){
      JFrame f = new JFrame("Feed Bean Example 2");
      f.setDefaultCloseOperation(2);
      f.add(new FeedBeanExample2());
      f.pack();
      f.setVisible(true);
    }
    class Feed {
        private long id = 0;
        private String name;
        private String siteUrl;
        private String feedUrl;
        private FeedType feedType;
        private boolean customCheckIntervalEnabled = false;
        private Integer checkInterval;

        public Feed() {
        }

        public Feed(String name, String siteUrl, String feedUrl, FeedType feedType) {
            this.name = name;
            this.siteUrl = siteUrl;
            this.feedUrl = feedUrl;
            this.feedType = feedType;
        }

        public long getId() {
            return id;
        }

        public void setId(long id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String newName) {
            this.name = newName;
        }

        public String getSiteUrl() {
            return siteUrl;
        }

        public void setSiteUrl(String newSiteUrl) {
            this.siteUrl = newSiteUrl;
        }

        public String getFeedUrl() {
            return feedUrl;
        }

        public void setFeedUrl(String newFeedUrl) {
            this.feedUrl = newFeedUrl;
        }

        public FeedType getFeedType() {
            return feedType;
        }

        public void setFeedType(FeedType newFeedType) {
            this.feedType = newFeedType;
        }

        public boolean isCustomCheckIntervalEnabled() {
            return customCheckIntervalEnabled;
        }

        public void setCustomCheckIntervalEnabled(boolean newCustomCheckIntervalEnabled) {
            this.customCheckIntervalEnabled = newCustomCheckIntervalEnabled;
        }

        public Integer getCheckInterval() {
            return checkInterval;
        }

        public void setCheckInterval(Integer newCheckInterval) {
            this.checkInterval = newCheckInterval;
        }

        public String toString() {
            return this.name;
        }
    }


    class FeedType {
        private String type;

        private FeedType(String type) {
            this.type = type;
        }

        public boolean equals(Object o) {
            if (this == oreturn true;
            if (!(instanceof FeedType)) return false;

            final FeedType feedType = (FeedTypeo;

            if (type != null ? !type.equals(feedType.type: feedType.type != nullreturn false;

            return true;
        }

        public int hashCode() {
            return (type != null ? type.hashCode() 0);
        }

        public String toString() {
            return this.type;
        }


    }

}

           
       
jgoodiesDataBinding.zip( 254 k)
Related examples in the same category
1. 表明三种不同的提交风格变化表明三种不同的提交风格变化
2. 建立了编辑器的组件绑定到域对象属性建立了编辑器的组件绑定到域对象属性
3. 使用缓冲适应ValueModels所造成的PresentationModel使用缓冲适应ValueModels所造成的PresentationModel
4. 从数据域复制数据建立一个文本编辑器从数据域复制数据建立一个文本编辑器
5. JGoodies数据绑定:选择名单组件频道范例JGoodies数据绑定:选择名单组件频道范例
6. JGoodies数据绑定:选择列表范例JGoodies数据绑定:选择列表范例
7. JGoodies数据绑定:选择名单典范JGoodies数据绑定:选择名单典范
8. JGoodies数据绑定:切换按钮适配器范例JGoodies数据绑定:切换按钮适配器范例
9. JGoodies数据绑定:值范例JGoodies数据绑定:值范例
10. JGoodies数据绑定:抽象表模式JGoodies数据绑定:抽象表模式
11. JGoodies数据绑定:基本元件厂范例JGoodies数据绑定:基本元件厂范例
12. JGoodies数据绑定:组件适配器范例JGoodies数据绑定:组件适配器范例
13. JGoodies数据绑定:有限范围适配器范例JGoodies数据绑定:有限范围适配器范例
14. JGoodies数据绑定:缓冲介绍典范JGoodies数据绑定:缓冲介绍典范
15. JGoodies数据绑定:组合适配器范例JGoodies数据绑定:组合适配器范例
16. JGoodies数据绑定:转换厂范例JGoodies数据绑定:转换厂范例
17. JGoodies数据绑定:提供组件范例1JGoodies数据绑定:提供组件范例1
18. JGoodies数据绑定:提供组件范例3JGoodies数据绑定:提供组件范例3
19. JGoodies数据绑定:介绍组件频道范例JGoodies数据绑定:介绍组件频道范例
20. JGoodies数据绑定:介绍组件属性变化监听范例JGoodies数据绑定:介绍组件属性变化监听范例
21. JGoodies数据绑定:演示模型属性变化范例JGoodies数据绑定:演示模型属性变化范例
22. JGoodies数据绑定:组件属性适配器范例1JGoodies数据绑定:组件属性适配器范例1
23. JGoodies数据绑定:组件属性适配器范例2JGoodies数据绑定:组件属性适配器范例2
24. JGoodies数据绑定:组件属性适配器范例3JGoodies数据绑定:组件属性适配器范例3
25. JGoodies数据绑定:组件属性的连接器范例JGoodies数据绑定:组件属性的连接器范例
26. JGoodies数据绑定:单选按钮适配器范例JGoodies数据绑定:单选按钮适配器范例
27. Swingx :图形界面数据绑定Swingx :图形界面数据绑定
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.