我要做个面板,上面有个时钟,然后还有个按钮可以动态改变面板的背景图片,同时不影响时钟的显示,请问怎样做?谢谢.

解决方案 »

  1.   

    如果是在同一个面板上,重写paintConponent方法,把时钟和背景都画上
      

  2.   

    class Clock extends JPanel{
        private BufferedImage backgroundImage = null;
        
        ... // 其他方法    public void setBackgroundImage(BufferedImage image){
    this.backgroundImage = image;
    repaint();
        }    public void paintComponent(Graphics g){
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D)g; if(backgroundImage != null){
        g2d.drawImage(backgroundImage,0,0);
    }

    ... // 其他绘制
        }
    }