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

📄 rangebeancustomizer.java~45~

📁 java bean 编程程序
💻 JAVA~45~
字号:
package chapter8;

import java.awt.*;
import javax.swing.*;
import java.beans.Customizer;
import java.beans.PropertyChangeListener;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyVetoException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class RangeBeanCustomizer
    extends JPanel
    implements Customizer
{
    XYLayout xYLayout1 = new XYLayout();
    JLabel jLabel1 = new JLabel();
    JTextField fromFld = new JTextField();
    JLabel jLabel2 = new JLabel();
    JTextField toFld = new JTextField();
    JLabel jLabel3 = new JLabel();
    String[] lblStyles = {"英文标签","中文标签","数学标签"};
    JComboBox lblStyleCmbox = new JComboBox(lblStyles);
    JButton okBtn = new JButton();
    JButton cancelBtn = new JButton();
    private transient PropertyChangeSupport pcs = new
        PropertyChangeSupport(this);
    private RangeBean oldRangeBean ;
    private int oldFrom ;
    private int oldTo;
    private int oldLblStyle;

    public RangeBeanCustomizer()
    {
        try
        {
            jbInit();
        }
        catch (Exception exception)
        {
            exception.printStackTrace();
        }
    }

    private void jbInit()
        throws Exception
    {
        this.setLayout(xYLayout1);
        jLabel1.setText("下限值");
        jLabel2.setText("上限值");
        jLabel3.setText("标签样式");
        okBtn.setText("确定"); okBtn.addActionListener(new
            RangeBeanCustomizer_okBtn_actionAdapter(this));
        cancelBtn.setText("取消");
        this.add(jLabel2, new XYConstraints(182, 25, -1, -1)); this.add(
            jLabel3, new XYConstraints(57, 62, -1, -1)); this.
            add(jLabel1, new XYConstraints(65, 26, -1, -1)); this.
            add(fromFld, new XYConstraints(102, 23, 64, -1)); this.add(
                toFld, new XYConstraints(231, 23, 62, -1)); this.add(cancelBtn,
            new XYConstraints(188, 95, -1, -1)); this.add(okBtn,
            new XYConstraints(112, 95, -1, -1)); this.add(lblStyleCmbox,
            new XYConstraints(102, 56, 191, -1));
    }

    public void setObject(Object bean)
    {
       if (bean instanceof RangeBean)
       {
           oldRangeBean = (RangeBean)bean;
           oldFrom = oldRangeBean.getFrom();
           oldTo   = oldRangeBean.getTo();
           oldLblStyle = oldRangeBean.getLblStyle();
           fromFld.setText(""+oldFrom);
           toFld.setText(""+oldTo);
           lblStyleCmbox.setSelectedIndex(oldLblStyle);
       }
    }

    public synchronized void addPropertyChangeListener(PropertyChangeListener
        l)
    {
        super.addPropertyChangeListener(l);
        if (pcs == null)
            pcs = new PropertyChangeSupport(this);
        pcs.addPropertyChangeListener(l);
    }
    public synchronized void removePropertyChangeListener(
        PropertyChangeListener l)
    {
        super.removePropertyChangeListener(l);
        if (pcs == null)
            pcs = new PropertyChangeSupport(this);
        pcs.removePropertyChangeListener(l);
    }

    //更新from的值
    private void changeFromProperty(Integer newFrom) throws PropertyVetoException
    {
       Integer currentFrom = new Integer(oldRangeBean.getFrom());
       oldRangeBean.setFrom(newFrom.intValue());
       if(pcs != null)
         pcs.firePropertyChange("from", currentFrom, newFrom);
    }

    //更新to的值
    private void changeToProperty(Integer newTo) throws PropertyVetoException
    {
       Integer currentTo = new Integer(oldRangeBean.getTo());
       oldRangeBean.setTo(newTo.intValue());
       if(pcs != null)
         pcs.firePropertyChange("to", currentTo, newTo);
    }

    //更新lblStyle的值
    private void changeLblStyleProperty(Integer newLblStyle) throws PropertyVetoException
    {
       Integer currentLblStyle = new Integer(oldRangeBean.getLblStyle());
       oldRangeBean.setTo(newLblStyle.intValue());
       if(pcs != null)
         pcs.firePropertyChange("lblStyle", currentLblStyle, newLblStyle);
    }

    public void okBtn_actionPerformed(ActionEvent e)
    {
        try
        {
            int newFrom = (new Integer(fromFld.getText())).intValue();
            int newTo   = (new Integer(toFld.getText())).intValue();
            int newLblStyle = lblStyleCmbox.getSelectedIndex();
            if (newFrom <= newTo)
            {
                JOptionPane.showMessageDialog(this,"下限值必须大于等于上限值","值设置错误",JOptionPane.OK_OPTION);
                return ;
            }
        }
        catch (NumberFormatException ex)
        {
            JOptionPane.showMessageDialog(this,"上下限值必须是整数型值","值设置错误",JOptionPane.OK_OPTION);
            return ;
        }
    }
}

class RangeBeanCustomizer_okBtn_actionAdapter
    implements ActionListener
{
    private RangeBeanCustomizer adaptee;
    RangeBeanCustomizer_okBtn_actionAdapter(RangeBeanCustomizer adaptee)
    {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e)
    {
        adaptee.okBtn_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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