Code example for EventObject

Methods: getSource

0
        return name + ":  " + oldValue + " => " + newValue;
    } 
 
    class ButtonListener implements DemoButtonListener, Serializable {
        public void buttonPressed(EventObject event) {
            DemoButton button = (DemoButton) event.getSource();
            try { 
                if (button == textButton) {
                    int index = (int) (Math.random() * texts.length);
                    bean.setText(texts[index]);
                    bean.repaint();
                } 
                if (button == colorButton) {
                    bean.setColor(new Color((int) (Math.random() * 255 * 255 * 255)));
                    bean.repaint();
                } 
                if (button == dimensionButton) {
                    Dimension size = getSize();
                    int width = 20 + (int) (Math.random() * size.width);
                    int height = 5 + (int) (Math.random() * size.height);
                    bean.setDimension(new Dimension(width, height));