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

📄 buttonbean.java

📁 java2 primer plus一书源程序
💻 JAVA
字号:
/* * ButtonBean.java * * Created on August 28, 2002, 11:38 AM */package com.samspublishing.jpp.ch15;import java.awt.*;import java.awt.event.*;import java.beans.*;import java.io.Serializable;import java.util.Vector;/** * * @author  Stephen Potts * @version */public class ButtonBean extends Component implements Serializable{    private boolean debug;    private PropertyChangeSupport pcs=       new PropertyChangeSupport(this);    private String label;            /** Creates new ButtonBean */    public ButtonBean()    {        this("ButtonBean");    }        public ButtonBean(String label)    {        super();        this.label = label;        setFont(new Font("Dialog", Font.PLAIN, 12));        setBackground(Color.lightGray);    }        public synchronized void paint(Graphics g)    {        int width = getSize().width;        int height = getSize().height;                g.setColor(getBackground());        g.fill3DRect(0, 0, width-1, height-1, false);                g.setColor(getForeground());        g.setFont(getFont());                g.drawRect(2, 2, width-4, height-4);                g.drawString(label, 10, 18);    }        public void addPropertyChangeListener(PropertyChangeListener pcl)    {        pcs.addPropertyChangeListener(pcl);    }        public void removePropertyChangeListener(PropertyChangeListener pcl)    {        pcs.addPropertyChangeListener(pcl);    }            public void setDebug(boolean x)    {        boolean old = debug;        debug = x;        pcs.firePropertyChange("debug", new Boolean(old),        new Boolean(x));    }        public boolean getDebug()    {        return debug;    }           public void setFontSize(int x)    {        Font old = getFont();        setFont(new Font(old.getName(), old.getStyle(), x));        pcs.firePropertyChange("fontSize",        new Integer(old.getSize()), new Integer(x));    }        public int getFontSize()    {        return getFont().getSize();    }        public void setFont(Font f)    {        Font old = getFont();        super.setFont(f);        pcs.firePropertyChange("font", old, f);    }        public void setLabel(String lab)    {        String oldLabel = label;        label = lab;        pcs.firePropertyChange("label", oldLabel, lab);    }        public String getLabel()    {        return label;    }        public Dimension getPreferredSize()    {        FontMetrics fm = getFontMetrics(getFont());        return new Dimension(fm.stringWidth(label) + 12,        fm.getMaxAscent() + fm.getMaxDescent() + 8);    }        public void setForeground(Color c)    {        Color old = getForeground();;        super.setForeground(c);        pcs.firePropertyChange("foreground", old, c);        repaint();    }        public void setBackground(Color c)    {        Color old = getBackground();;        super.setBackground(c);        pcs.firePropertyChange("background", old, c);        repaint();    }}//class

⌨️ 快捷键说明

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