Results 1 to 5 of 5

Thread: How to use Graphics in Java?

  1. #1
    Join Date
    Aug 2006
    Posts
    142

    How to use Graphics in Java?

    hello everyone,
    I am new to the Java which I started recently. Before that I have did the C++ and HTML programming language. In C++ I have used the graphics to some extent. But now I want to use the graphics for the Java.!! So need your help..!! Please tell me how to use Graphics in Java? Help me as soon as possible.
    ~HARE KRISHNA HARE RAM~

  2. #2
    Join Date
    Aug 2006
    Posts
    227

    Re: How to use Graphics in Java?

    You will have to use the Graphics in Java, whenever you want to draw or color the graphics that you have created. You also need Graphics class for creating the graphics. The methods that are included in the Graphics class, can be categorized into two basic groups :
    1. You can draw and fill the methods by which you are enabled to render basic shapes, text, and images.
    2. The other part are the attributes setting methods, which affect how that drawing and filling appears.
    I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.

  3. #3
    Join Date
    Jul 2006
    Posts
    442

    Re: How to use Graphics in Java?

    You can also use the Graphics in a Java Applet. For using that in Applet, you can follow the steps mentioned below :
    1. First, you will have to locate the paint method created by you. Then set the parameter for a graphics class.
    2. In your code part, write the statement :
      Code:
      public void paint (Graphics g).
    3. Later you will have to set up your draw line method in the graphics class. For doing this you must set the proper coordinates in sequence.
    4. You will have to call the specific method for importing and drawing an images to your object. For this you will have to import java.awt.Image.
    "When they give you ruled paper, write the other way..." J.R.J.

  4. #4
    Join Date
    Jul 2006
    Posts
    289

    Re: How to use Graphics in Java?

    The following information is the most important that you will have to know before doing the coding for graphics. The drawings method includes the following things :
    1. drawString - This is used for drawing the Text.
      Code:
      g.drawString("Welcome", 20, 20);
    2. drawImage - This is used for drawing an images.
      Code:
      g.drawImage(img, 
                         0, 0, width, height,
                         0, 0, imageWidth, imageHeight,
                        null);
    Signatures reduce available bandwidth

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    Re: How to use Graphics in Java?

    If you want to fill the rectangle with the colors that you want, then you will have to use the fillRect method. This method allows you to draw a rectangle filled with the specified color. The following sample of code demonstrates the same :
    Code:
    ...
            Rectangle2D boundsT = font.getStringBounds(tempString, frc);
            Rectangle2D boundsC = font.getStringBounds(condStr, frc);
            int wText = Math.max((int)boundsTemp.getWidth(), (int)boundsCond.getWidth());
            int hText = (int)boundsTemp.getHeight() + (int)boundsCond.getHeight();
            int rX = (size.width-wText)/2;
            int rY = (size.height-hText)/2;
            
            g.setColor(Color.LIGHT_BLUE);
            g2.fillRect(rX, rY, wText, hText);
    	...

Similar Threads

  1. Replies: 8
    Last Post: 20-11-2011, 05:33 PM
  2. Java ME Games and Graphics Online Training Course
    By derrik in forum Education Career and Job Discussions
    Replies: 1
    Last Post: 12-05-2010, 12:09 AM
  3. Help: Java swing JPanel to repaint PaintComponent( Graphics g )
    By grudge in forum Software Development
    Replies: 4
    Last Post: 22-07-2009, 07:05 PM
  4. C++ or Java for Non API Based 3D Graphics
    By Segvoia in forum Software Development
    Replies: 4
    Last Post: 25-02-2009, 10:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,052,031.28487 seconds with 17 queries