⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datebeancustomizer.java

📁 Java实例入门
💻 JAVA
字号:
package beantest;import java.beans.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;/** * Title:        制作一个JavaBean * Description:  这个工程中我们制作了一个用于日期显示的JavaBean * Copyright:    Copyright (c) 2001 * Company: * @author * @version 1.0 */public class DateBeanCustomizer extends JPanel implements Customizer  ,ActionListener{  // variables used by the Customizer  PropertyChangeSupport pcs = null;  DateBean bean = null;  Integer oldStyle = null;  Boolean oldUseMonthString = null;  // variables used for UI design  BorderLayout borderLayout1 = new BorderLayout();  JPanel southPanel = new JPanel();  FlowLayout fL1 = new FlowLayout();  JPanel buttonPanel = new JPanel();  GridLayout gL1 = new GridLayout();  JLabel title = new JLabel();  JPanel centerPanel = new JPanel();  BorderLayout bL2 = new BorderLayout();  ChoicePanel choices = new ChoicePanel();  JPanel eastPanel = new JPanel();  JCheckBox useMS = new JCheckBox();  public DateBeanCustomizer() {}  public void setObject(Object in) {       try { jbInit(); } catch (Exception e) { e.printStackTrace(); }      if(in instanceof DateBean){      bean = (DateBean)in;      // capture old state values for use by revert      oldStyle = new Integer(bean.getStyle());      oldUseMonthString = new Boolean(bean.isUseMonthString());      // seed the customizer with copies the right settings for the current copy      choices.setSelectedItem(bean.getStyle());      useMS.setSelected(bean.isUseMonthString());      }    else      System.out.println("how'd that happen?");  }   // called when changing the useMonthString property  private void changeUseMonthStringProperty(Boolean newValue){    Boolean currentStyle = new Boolean(bean.isUseMonthString());    bean.setUseMonthString(newValue.booleanValue());    if(pcs != null)      pcs.firePropertyChange("useMonthString", currentStyle, newValue);  }  // called when changing the style property  private void changeStyleProperty(Integer newValue){    Integer currentStyle = new Integer(bean.getStyle());    bean.setStyle(newValue.intValue());    if(pcs != null)      pcs.firePropertyChange("style", currentStyle, newValue);  }  // Constructs the UI for the Customizer  private void jbInit() throws Exception {    this.setLayout(borderLayout1);    southPanel.setLayout(fL1);    fL1.setAlignment(2);    gL1.setColumns(1);    gL1.setHgap(5);    title.setText("Date Bean Customizer");    useMS.setText("Use Month String");    useMS.addItemListener(new java.awt.event.ItemListener() {      public void itemStateChanged(ItemEvent e) {        useMS_itemStateChanged(e);      }    });    centerPanel.setLayout(bL2);    buttonPanel.setLayout(gL1);    this.add(southPanel, BorderLayout.SOUTH);    southPanel.add(buttonPanel, null);    this.add(title, BorderLayout.NORTH);    this.add(centerPanel, BorderLayout.CENTER);    centerPanel.add(choices, BorderLayout.CENTER);    centerPanel.add(eastPanel, BorderLayout.EAST);    eastPanel.add(useMS, null);    choices.addActionListener(this);  }  // Use Insets to make UI stand out when reparented by an IDE  public Insets getInsets(){ return new Insets(5,5,5,5); }  public void addPropertyChangeListener(PropertyChangeListener listener) {     if(pcs == null)      pcs = new PropertyChangeSupport(this);    pcs.addPropertyChangeListener(listener);  }  public void removePropertyChangeListener(PropertyChangeListener listener) {   if(pcs != null)      pcs.removePropertyChangeListener(listener);  }   public void actionPerformed(ActionEvent e) {    changeStyleProperty(new Integer(e.getID()));  }  void useMS_itemStateChanged(ItemEvent e) {    changeUseMonthStringProperty(new Boolean(useMS.isSelected()));  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -