Results 1 to 6 of 6

Thread: Graphics2D class of java

  1. #1
    Join Date
    Jan 2010
    Posts
    64

    Graphics2D class of java

    Hi friends,

    I am new to the classes of java programming language. In which I just started to learn the inbuilt classes of java. The Graphics2D class seems very complicated to understand as compare to other java inbuilt classes. I don't know anything about the methods of Graphics2D class of java. If you posses sound knowledge about the Graphics2D class, then please let me know that same. I would really appreciate your any help over Graphics2D class.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: Graphics2D class of java

    This Graphics2D class extends the Graphics class to provide more sophisticated control over geometry, coordinate transformations, color management, and text layout. This is the fundamental class for rendering 2-dimensional shapes, text and images on the Java platform. All coordinates passed to a Graphics2D object are specified in a device-independent coordinate system called User Space, which is used by applications.The Graphics2D object contains an AffineTransform object as part of its rendering state that defines how to convert coordinates from user space to device-dependent coordinates in Device Space.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Graphics2D class of java

    Hi,

    Please refer following example of Graphics2D class of java programming:
    Code:
    import java.awt.Graphics2D;
    import javax.swing.JFrame;
    public class Graphics2DSample
    {
      public static void main(String[] afrgs) {
        JFrame jf01 = new JFrame("Demo");
        Container cp1 = jf01.getContentPane();
        MyCanvas tl = new MyCanvas();
        cp1.add(tl);
        jf01.setSize(300, 200);
        jf01.setVisible(true);
      }}
    class MyCanvas extends JComponent {
      Shape shape;
    
      public MyCanvas() {
        shape1 = create();
      }
      protected Shape create() {
        GeneralPath path = new GeneralPath();
        path1.moveTo(60, 30);
        path1.lineTo(50, 200);
        return path;
      }
      public void paint(Graphics g1) {
        Graphics2D g02 = (Graphics2D) g1;
        g02.setPaint(Color.black);
        g02.draw(shape);
      }
    }

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Graphics2D class of java

    Hello friend,

    If you want to know about the methods of Graphics2D class, then review following:
    • translate(int xn, int yn)
    • transform(AffineTransform Tx)
    • setTransform(AffineTransform Txm)
    • setRenderingHint(RenderingHints.Key hintKey, Object hintVal)
    • setComposite(Composite comp)
    • setBackground(Color clr)

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Graphics2D class of java

    Example of Graphics2D class:
    Code:
    import java.awt.Graphics2D;
    import javax.swing.JPanel;
    
    public class GPMainClass extends JPanel {
      public void paint(Graphics gV) {
        g.fillRect(0, 0, 30, 30);
        Graphics2D gp2 = (Graphics2D) g;
        gp2.translate(50, 50);
        gp2.rotate(30.0 * Math.PI / 180.0);
        gp2.scale(2.0, 2.0);
        gV.setColor(Color.red);
        gV.fillRect(0, 0, 30, 30);
      }
      public static void main(String[] arcgs) {
        JFrame ZLP = new JFrame();
        ZLP.getContentPane().add(new MainClass());
        ZLP.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ZLP.setSize(200, 200);
        ZLP.setVisible(true);
      }
    }

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

    Re: Graphics2D class of java

    Hi friend,

    Below I have given some constructors of Graphics2D class, review it carefully:
    1. getDeviceConfiguration
    2. drawRenderedImage
    3. getFontRenderContext
    4. drawGlyphVector
    5. drawRenderableImage

Similar Threads

  1. Converting java class to java bean class
    By Ucchal in forum Software Development
    Replies: 6
    Last Post: 09-08-2010, 10:24 AM
  2. KeyboardFocusManager class of java
    By Gokul20 in forum Software Development
    Replies: 4
    Last Post: 05-03-2010, 03:38 PM
  3. JDesktopPane class of java
    By Sonam Goenka in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 08:14 AM
  4. RecordStore class in java
    By Level8 in forum Software Development
    Replies: 4
    Last Post: 12-12-2009, 02:12 PM
  5. Java Programming Language Basics: Reflection Basics and Class Class
    By mayuri_gunjan in forum Guides & Tutorials
    Replies: 6
    Last Post: 29-08-2005, 12:04 AM

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,750,902,301.58994 seconds with 16 queries