Produce color verification code_ (JavaBean implementation)
File name: image.java ============================================ ====================== / ** Created on 2004-8-4 ** to change the template for this generated file go to * window> preferences> Java > Code Generation> Code and Comments * / package myclass.test; import java.awt. *; Import java.awt.image. *; Import java.util. *; / *** @author ** to change the template fortfor ** to change the Template for This Generated Type Comment Go To * Window> Preferences> Java> Code Generation> Code and Comments * / Public Class Image {Public String Srand = ""; Public Color GetrandColor (int FC, int BC) {// given ranging from random Color random random = new random (); if (fc> 255) Fc = 255; if (bc> 255) BC = 255; int R = fc random.nextint (BC-FC); int G = fc random. Nextint (BC-FC); int b = fc random.nextint (BC-FC); Return New Color (R, G, B);} public bufferedImage Creatimage () {// Create image in memory int width = 60, height = 20; BufferedImage image = new BufferedImage (width, height, BufferedImage.TYPE_INT_RG; // Get the graphics context graphics g = image.getGraphics (); // class generating a random random random = new random (); // set Set Color G.SetColor (GetrandColor (200, 250)); G.FillRect (0 , 0, width, height); // Set font G.SetFont (New Font ("Times New Roman", Font.Plain, 18)); // Section Box //g.SetColor (New Color ()); //g.drawRect (0, 10 ,width-1, height-1) ;/ randomly generate 155 interferent lines, enabling the authentication code in the image to detect G.SetColor (GetrandColor (160,200)) FOR (int i = 0; i <155; i ) {int x = random.nextint (width); int y = random.nextint (INT XL = random.nextint (12);