内部类中来实现actionListener接口 重写actionPerformed 有关颜色

里用内部类,可以实现多个按钮事件。

内部的两个类

/*class LabelListener implements ActionListener{
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            label.setText("我已经改变咯!");
        }

    }
    class ColorListener implements ActionListener{
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            frame.repaint();
        }

    }*/

实现指定的监听

/*labelbutton.addActionListener(new LabelListener());//实现两个监听
        colorbutton.addActionListener(new ColorListener());*/

颜色
Graphics g;
g.setColor(Color.white);
g.fillRect(0,0,500,250);// 填充范围

猜你喜欢

转载自blog.csdn.net/so_band/article/details/80834766
今日推荐