Java Web Verification Code

Source: Internet
Author: User

Package tk. donghongyujava. util; import java. awt. color; public class RandomImage {private final static int WIDTH = 100; private final static int HEIGHT = 30; public static Random rd = new Random (); public static BufferedImage creatImage () {// draw the image BufferedImage image = new BufferedImage (WIDTH, HEIGHT, BufferedImage. TYPE_INT_BGR); // obtain the paint brush Graphics g = image. getGraphics (); // set the background drawBackground (g); // draw the border drawBorder (g); // draw the content drawContent (g); // draw the interference drawDisturb (g ); return image;} private static void drawContent (Graphics g) {// TODO Auto-generated method stubString con = "inline"; StringBuffer sb = new StringBuffer (); for (int I = 0; I <4; I ++) {int index = rd. nextInt (con. length (); char str = con. charAt (index); sb. append (str + "");} g. setColor (Color. black); g. setFont (new Font ("Gungsuh", Font. BOLD, 20); g. drawString (sb. toString (), 15, 20);} private static void drawDisturb (Graphics g) {// TODO Auto-generated method stubg. setColor (Color. BLUE); for (int I = 0; I <4; I ++) {int x1 = rd. nextInt (WIDTH); int y1 = rd. nextInt (HEIGHT); int x2 = rd. nextInt (WIDTH); int y2 = rd. nextInt (HEIGHT); g. drawLine (x1, y1, x2, y2);} g. setColor (Color. red); g. drawOval (30, 20, 2, 2);} private static void drawBorder (Graphics g) {// TODO Auto-generated method stubg. setColor (Color. yellow); g. drawRect (0, 0, WIDTH-2, HEIGHT-2);} private static void drawBackground (Graphics g) {// TODO Auto-generated method stubg. setColor (Color. green); g. fillRect (0, 0, WIDTH, HEIGHT );}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.