请问有谁知道验证码上的字体,怎么让他改变颜色啊 ?

解决方案 »

  1.   

    Graphics   gra=image.getGraphics();     
      //设置背景色     
      gra.setColor(Color.yellow);     
        
      gra.fillRect(1,1,33,12);     
      //设置字体色     
      gra.setColor(Color.black); 
      

  2.   

    下面是我设置字体颜色的方法:
    其中code是一个数组,里面存放4个字;
    因此,我就设置这4个字体的颜色;
    怎么没有反应啊?
    不知道错在哪里?
    帮我看看?
    public void setColor(Graphics graphics){
         Graphics2D g = (Graphics2D)graphics;
    //     Random random=new Random();
    //     for(int i=0;i<this.codes.length;i++){
    //     graphics.drawString(String.valueOf(this.codes[i]), this.bufferedImage.getHeight(), this.bufferedImage.getWidth());
    //     graphics.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
    // //graphics.drawString(sb.toString(), 13*i+6, 16);
    //     }
         graphics.drawString(String.valueOf(this.codes[0]), this.bufferedImage.getHeight(),this.bufferedImage.getWidth());
         g.setColor(Color.RED);
         graphics.drawString(String.valueOf(this.codes[1]), this.bufferedImage.getHeight(),this.bufferedImage.getWidth());
         g.setColor(Color.BLUE);
         graphics.drawString(String.valueOf(this.codes[2]), this.bufferedImage.getHeight(),this.bufferedImage.getWidth());
         g.setColor(Color.BLACK);
         graphics.drawString(String.valueOf(this.codes[3]), this.bufferedImage.getHeight(),this.bufferedImage.getWidth());
         g.setColor(Color.green);
        
        }