KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > awt > Graphics2D

java.awt
Class Graphics2D

java.lang.Object
  extended by java.awt.Graphics
      extended by java.awt.Graphics2D
See Also:
Top Examples, Source Code, draw, fill, KEY_STROKE_CONTROL, VALUE_ANTIALIAS_ON, VALUE_ANTIALIAS_OFF, KEY_ANTIALIASING, AlphaComposite.SRC_OVER, getDefaultTransform, drawImage(Image, AffineTransform, ImageObserver), GlyphVector, TextLayout, AttributedCharacterIterator, PaintContext, Paint, getPathIterator, PathIterator, getPathIterator, createStrokedShape, Composite, Image, Component, AffineTransform

public abstract void addRenderingHints(Map<?,?> hints)
See Also:
RenderingHints
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[547]Add RenderingHints to a Graphics
By myxucrute { at } yahoo { dot } com on 2003/11/27 07:37:32  Rate
protected void paintComponent ( Graphics g )   {  
    Graphics2D g2d =  ( Graphics2D ) g; 
    g2d.addRenderingHints ( new RenderingHints ( RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON )  ) ; 
  } 


public abstract void clip(Shape s)
See Also:
setClip
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void draw(Shape s)
See Also:
setComposite(java.awt.Composite), Graphics.setClip(int, int, int, int), clip(java.awt.Shape), setTransform(java.awt.geom.AffineTransform), transform(java.awt.geom.AffineTransform), Graphics.setColor(java.awt.Color), setPaint(java.awt.Paint), setStroke(java.awt.Stroke)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void draw3DRect(int x,
                       int y,
                       int width,
                       int height,
                       boolean raised)
See Also:
Graphics.fill3DRect(int, int, int, int, boolean)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void drawGlyphVector(GlyphVector g,
                                     float x,
                                     float y)
See Also:
Graphics.setClip(int, int, int, int), setComposite(java.awt.Composite), setTransform(java.awt.geom.AffineTransform), Graphics.setColor(java.awt.Color), setPaint(java.awt.Paint), Font.createGlyphVector(java.awt.font.FontRenderContext, java.lang.String)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract boolean drawImage(Image img,
                                  AffineTransform xform,
                                  ImageObserver obs)
See Also:
Graphics.setClip(int, int, int, int), clip(java.awt.Shape), setComposite(java.awt.Composite), setTransform(java.awt.geom.AffineTransform), transform(java.awt.geom.AffineTransform)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void drawImage(BufferedImage img,
                               BufferedImageOp op,
                               int x,
                               int y)
See Also:
Graphics.setClip(int, int, int, int), clip(java.awt.Shape), setComposite(java.awt.Composite), setTransform(java.awt.geom.AffineTransform), transform(java.awt.geom.AffineTransform)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void drawRenderableImage(RenderableImage img,
                                         AffineTransform xform)
See Also:
drawRenderedImage(java.awt.image.RenderedImage, java.awt.geom.AffineTransform), Graphics.setClip(int, int, int, int), clip(java.awt.Shape), setComposite(java.awt.Composite), setTransform(java.awt.geom.AffineTransform), transform(java.awt.geom.AffineTransform)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void drawRenderedImage(RenderedImage img,
                                       AffineTransform xform)
See Also:
Graphics.setClip(int, int, int, int), clip(java.awt.Shape), setComposite(java.awt.Composite), setTransform(java.awt.geom.AffineTransform), transform(java.awt.geom.AffineTransform)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void drawString(String s,
                                float x,
                                float y)
See Also:
Graphics.setClip(int, int, int, int), setComposite(java.awt.Composite), setTransform(java.awt.geom.AffineTransform), Graphics.setFont(java.awt.Font), Graphics.setColor(java.awt.Color), setPaint(java.awt.Paint), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void drawString(String str,
                                int x,
                                int y)
See Also:
Graphics.drawChars(char[], int, int, int, int), Graphics.drawBytes(byte[], int, int, int, int), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[72]Draw a string with AffineTransform
By Anonymous on 2004/04/14 07:18:30  Rate
import java.awt.*; 
 import java.awt.event.*; 
 import java.awt.geom.*; 
 import javax.swing.*; 
      
 class myComponent extends JComponent  {  
   private static final int N = 300; 
      
   public Dimension getPreferredSize (  )   {  
     return new Dimension ( N, N ) ; 
    }  
      
   public void paint ( Graphics g )   {  
     Graphics2D g2d =  ( Graphics2D ) g; 
      
     AffineTransform aft = AffineTransform. 
       getRotateInstance ( Math.PI, N / 2, N / 2 ) ; 
     g2d.setTransform ( aft ) ; 
      
     Font f = new Font ( "monospaced", Font.BOLD, 24 ) ; 
     g2d.setFont ( f ) ; 
     String s = "testing"; 
     g2d.drawString ( s, 100, 100 ) ; 
     FontMetrics fm = getFontMetrics ( f ) ; 
     int h = fm.getHeight (  ) ; 
     int w = fm.stringWidth ( s ) ; 
     g2d.drawLine ( 100, 100 + h, 100 + w, 100 + h ) ; 
    }  
  }  
      
 public class graph2d  {  
   public static void main ( String args [  ]  )   {  
     JFrame f = new JFrame ( "testing" ) ; 
     f.addWindowListener ( new WindowAdapter (  )   {  
       public void windowClosing ( WindowEvent e )   {  
         System.exit ( 0 ) ; 
        }  
      }  ) ; 
      
     JPanel p = new JPanel (  ) ; 
     p.add ( new myComponent (  )  ) ; 
     f.getContentPane (  ) .add ( p ) ; 
      
     f.pack (  ) ; 
     f.setVisible ( true ) ; 
    }  
  }  
 


[121]Testing drawString
By Anonymous on 2004/06/15 09:23:42  Rate
import java.awt.*;  
 import java.awt.event.*;  
 import java.awt.geom.*;  
 import javax.swing.*;  
       
 class myComponent extends JComponent  {   
   private static final int N = 300;  
       
   public Dimension getPreferredSize (  )   {   
     return new Dimension ( N, N ) ;  
    }   
       
   public void paint ( Graphics g )   {   
     Graphics2D g2d =  ( Graphics2D ) g;  
       
     String s = "Testing drawString";  
     Font f = new Font ( "Times New Roman", Font.PLAIN, 24 ) ;  
     g2d.setFont ( f ) ;  
     FontMetrics fm = getFontMetrics ( f ) ;  
     int h = fm.getHeight (  ) ;  
     int w = fm.stringWidth ( s ) ;  
     int d = fm.getMaxDescent (  ) ; 
     int x =  ( N - w ) /2; 
     int y = N/3; 
     g2d.drawString ( s, x, y ) ;  
     g2d.draw ( new Rectangle ( x, y + d - h, w, h )  ) ;  
     g2d.drawLine ( x, y, x + w, y ) ;  
    }   
  
  
   public static void main ( String args [  ]  )   {   
     JFrame f = new JFrame ( "Testing drawString" ) ;  
     f.addWindowListener ( new WindowAdapter (  )   {   
       public void windowClosing ( WindowEvent e )   {   
         System.exit ( 0 ) ;  
        }   
      }  ) ;  
       
     JPanel p = new JPanel (  ) ;  
     p.add ( new myComponent (  )  ) ;  
     f.getContentPane (  ) .add ( p ) ;  
       
     f.pack (  ) ;  
     f.setVisible ( true ) ;  
    }   
  }  


public abstract void drawString(AttributedCharacterIterator iterator,
                                float x,
                                float y)
See Also:
Graphics.setClip(int, int, int, int), setComposite(java.awt.Composite), setTransform(java.awt.geom.AffineTransform), Graphics.setColor(java.awt.Color), setPaint(java.awt.Paint)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[476]_
By Anonymous on 2003/10/27 13:01:07  Rate
import java.awt.*;   
 import java.awt.event.*;   
 import java.awt.geom.*;   
 import javax.swing.*;   
        
 class myComponent extends JComponent  {    
   private static final int N = 300;   
        
   public Dimension getPreferredSize (  )   {    
     return new Dimension ( N, N ) ;   
    }    
        
   public void paint ( Graphics g )   {    
     Graphics2D g2d =  ( Graphics2D ) g;   
        
     String s = "Testing drawString";   
     Font f = new Font ( "Times New Roman", Font.PLAIN, 24 ) ;   
     g2d.setFont ( f ) ;   
     FontMetrics fm = getFontMetrics ( f ) ;   
     int h = fm.getHeight (  ) ;   
     int w = fm.stringWidth ( s ) ;   
     int d = fm.getMaxDescent (  ) ;  
     int x =  ( N - w ) /2;  
     int y = N/3;  
     g2d.drawString ( s, x, y ) ;   
     g2d.draw ( new Rectangle ( x, y + d - h, w, h )  ) ;   
     g2d.drawLine ( x, y, x + w, y ) ;   
    }   


public abstract void drawString(AttributedCharacterIterator iterator,
                                int x,
                                int y)
See Also:
Graphics.setClip(int, int, int, int), setComposite(java.awt.Composite), setTransform(java.awt.geom.AffineTransform), Graphics.setColor(java.awt.Color), setPaint(java.awt.Paint)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1998]Java fdafd
By romanista2008 { at } gmail { dot } com on 2009/06/29 10:26:20  Rate
dfsabfdsavbfdsvabfd jfdvdf

public abstract void fill(Shape s)
See Also:
Graphics.setClip(int, int, int, int), clip(java.awt.Shape), setComposite(java.awt.Composite), setTransform(java.awt.geom.AffineTransform), transform(java.awt.geom.AffineTransform), Graphics.setColor(java.awt.Color), setPaint(java.awt.Paint)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void fill3DRect(int x,
                       int y,
                       int width,
                       int height,
                       boolean raised)
See Also:
Graphics.draw3DRect(int, int, int, int, boolean)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract Color getBackground()
See Also:
setBackground(java.awt.Color)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract Composite getComposite()
See Also:
setComposite(java.awt.Composite)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract GraphicsConfiguration getDeviceConfiguration()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract FontRenderContext getFontRenderContext()
See Also:
TextLayout, Font.createGlyphVector(java.awt.font.FontRenderContext, java.lang.String)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract Paint getPaint()
See Also:
Graphics.setColor(java.awt.Color), setPaint(java.awt.Paint)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract Object getRenderingHint(RenderingHints.Key hintKey)
See Also:
setRenderingHint(RenderingHints.Key, Object), RenderingHints
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract RenderingHints getRenderingHints()
See Also:
setRenderingHints(Map)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract Stroke getStroke()
See Also:
setStroke(java.awt.Stroke)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract AffineTransform getTransform()
See Also:
setTransform(java.awt.geom.AffineTransform), transform(java.awt.geom.AffineTransform)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected Graphics2D()
See Also:
Graphics.create(), Component.getGraphics(), BufferedImage
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract boolean hit(Rectangle rect,
                            Shape s,
                            boolean onStroke)
See Also:
Graphics.setClip(int, int, int, int), clip(java.awt.Shape), setTransform(java.awt.geom.AffineTransform), transform(java.awt.geom.AffineTransform), draw(java.awt.Shape), fill(java.awt.Shape), setStroke(java.awt.Stroke)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void rotate(double theta)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void rotate(double theta,
                            double x,
                            double y)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void scale(double sx,
                           double sy)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void setBackground(Color color)
See Also:
Graphics.clearRect(int, int, int, int), getBackground()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void setComposite(Composite comp)
See Also:
AWTPermission, SecurityManager.checkPermission(java.security.Permission), AlphaComposite, getComposite(), Graphics.setPaintMode(), Graphics.setXORMode(java.awt.Color), SecurityException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void setPaint(Paint paint)
See Also:
TexturePaint, GradientPaint, getPaint(), Graphics.setColor(java.awt.Color)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void setRenderingHint(RenderingHints.Key hintKey,
                                      Object hintValue)
See Also:
RenderingHints, getRenderingHint(RenderingHints.Key)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void setRenderingHints(Map<?,?> hints)
See Also:
RenderingHints, getRenderingHints()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void setStroke(Stroke s)
See Also:
getStroke(), BasicStroke
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void setTransform(AffineTransform Tx)
See Also:
getTransform(), transform(java.awt.geom.AffineTransform)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void shear(double shx,
                           double shy)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void transform(AffineTransform Tx)
See Also:
setTransform(java.awt.geom.AffineTransform)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void translate(double tx,
                               double ty)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void translate(int x,
                               int y)
See Also:
Graphics
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags