1 Reply Latest reply: May 15, 2013 6:02 AM by 947172 RSS

    Fill3DRect  Doesn’t Look 3D

      The following code should create a 3D rectangle image with text. The problem is there doesn’t seem to be any difference between the 3D rectangle raised (true) and not raised (false). Is there something I need to do to get a 3D effect or does it simply not work?




      package jservlets;

      import java.io.*;
      import java.util.*;
      import java.sql.*;

      import javax.servlet.*;
      import javax.servlet.http.*;

      import java.awt.Color;
      import java.awt.Font;
      import java.awt.Graphics2D;
      import java.awt.image.BufferedImage;
      import javax.imageio.ImageIO;

      public class CreateRectangleTest extends HttpServlet
      PrintWriter out;
      PrintWriter err;

      private void CreateButton(HttpServletRequest request, HttpServletResponse response) throws IOException
           out.println ("\n\n+++++ CreateButton Process +++++\n");
           int width = 250;
           int height = 250;

           // Constructs a BufferedImage of one of the predefined image types.
      BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

           // Create a graphics which can be used to draw into the buffered image
           Graphics2D g2d = bufferedImage.createGraphics();

      // create a rectangle with black

      //this will draw a filled 3-D rectangle of width 50 & height 100 at (10,10)


      g2d.setFont(new Font( "Arial", Font.BOLD, 15 ));      

      //create a string with yellow
      g2d.drawString("About Us", 20, 45);

      // Disposes of this graphics context and releases any system resources that it is using.

      // Save as PNG
      File file = new File("myimage.png");
      ImageIO.write(bufferedImage, "png", file);

      // Save as JPEG
      file = new File("myimage.gif");
      ImageIO.write(bufferedImage, "gif", file);
           catch (IOException sqlio)
                out.println("IOException: Could not execute Create Button.");
                err.println (sqlio.getMessage () ) ;      

      public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException
                out = response.getWriter();
                err = response.getWriter();
      CreateButton(request, response);


      catch (IOException io)
      err.println (io.getMessage () ) ;

           catch(Throwable io)


      public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException
      doPost(request, response);


      Edited by: 1004861 on May 9, 2013 8:24 PM