Awt-graphics2d-class

提供:Dev Guides
移動先:案内検索

AWT Graphics2Dクラス

前書き

Graphics2Dクラスは、Graphicsクラスを拡張して、ジオメトリ、座標変換、色管理、およびテキストレイアウトをより高度に制御できるようにします。

クラス宣言

以下は、 java.awt.Graphics2D クラスの宣言です。

public abstract class Graphics2D
   extends Graphics

クラスコンストラクター

S.N. Constructor & Description
1

Graphics2D()

新しいGraphics2Dオブジェクトを構築します。

クラスメソッド

S.N. Method & Description
1

abstract void addRenderingHints(Map<?,?> hints)

レンダリングアルゴリズムの任意の数の設定の値を設定します。

2

abstract void clip(Shape s)

現在のクリップを指定されたShapeの内部と交差させ、結果の交差にClipを設定します。

3

abstract void draw(Shape s)

現在のGraphics2Dコンテキストの設定を使用して、Shapeの輪郭をストロークします。

4

void draw3DRect(int x, int y, int width, int height, boolean raised)

指定された長方形の強調表示された3Dアウトラインを描画します。

5

abstract void drawGlyphVector(GlyphVector g, float x, float y)

Graphics2Dコンテキストのレンダリング属性を使用して、指定されたGlyphVectorのテキストをレンダリングします。

6

abstract void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)

BufferedImageOpでフィルター処理されたBufferedImageをレンダリングします。

7

abstract boolean drawImage(Image img, AffineTransform xform, ImageObserver obs)

画像をレンダリングし、描画する前に画像空間からユーザー空間への変換を適用します。

8

abstract void drawRenderableImage(RenderableImage img, AffineTransform xform)

RenderableImageをレンダリングし、描画前に画像空間からユーザー空間への変換を適用します。

9

abstract void drawRenderedImage(RenderedImage img, AffineTransform xform)

RenderedImageをレンダリングし、描画前に画像空間からユーザー空間への変換を適用します。

10

abstract void drawString(AttributedCharacterIterator iterator, float x, float y)

TextAttributeクラスの仕様に従って、その属性を適用して、指定された反復子のテキストをレンダリングします。

11

abstract void drawString(AttributedCharacterIterator iterator, int x, int y)

TextAttributeクラスの仕様に従って、その属性を適用して、指定された反復子のテキストをレンダリングします。

12

abstract void drawString(String str, float x, float y)

Graphics2Dコンテキストの現在のテキスト属性状態を使用して、指定された文字列で指定されたテキストをレンダリングします

13

abstract void drawString(String str, int x, int y)

Graphics2Dコンテキストの現在のテキスト属性状態を使用して、指定されたストリングのテキストをレンダリングします。

14

abstract void fill(Shape s)

Graphics2Dコンテキストの設定を使用して、Shapeの内部を塗りつぶします。

15

void fill3DRect(int x, int y, int width, int height, boolean raised)

現在の色で塗りつぶされた3D強調表示された四角形をペイントします。

16

abstract Color getBackground()

領域のクリアに使用される背景色を返します。

17

abstract Composite getComposite()

Graphics2Dコンテキストの現在のCompositeを返します。

18

abstract GraphicsConfiguration getDeviceConfiguration()

このGraphics2Dに関連付けられたデバイス構成を返します。

19

abstract FontRenderContext getFontRenderContext()

このGraphics2Dコンテキスト内のFontのレンダリングコンテキストを取得します。

20

abstract Paint getPaint()

Graphics2Dコンテキストの現在のペイントを返します。

21

abstract Object getRenderingHint(RenderingHints.Key hintKey)

レンダリングアルゴリズムの単一の設定の値を返します。

22

abstract RenderingHints getRenderingHints()

レンダリングアルゴリズムの設定を取得します。

23

abstract Stroke getStroke()

Graphics2Dコンテキストの現在のストロークを返します。

24

abstract AffineTransform getTransform()

Graphics2Dコンテキストの現在のTransformのコピーを返します。

25

abstract boolean hit(Rectangle rect, Shape s, boolean onStroke)

指定したShapeが、デバイス空間にある指定したRectangleと交差するかどうかを確認します。

26

abstract void rotate(double theta)

現在のGraphics2D変換と回転変換を連結します。

27

abstract void rotate(double theta, double x, double y)

現在のGraphics2D変換と、変換された回転変換を連結します。

28

abstract void scale(double sx, double sy)

現在のGraphics2D変換とスケーリング変換を連結します。後続のレンダリングは、以前のスケーリングに関連して指定されたスケーリング係数に従ってサイズ変更されます。

29

abstract void setBackground(Color color)

Graphics2Dコンテキストの背景色を設定します。

30

abstract void setComposite(Composite comp)

Graphics2DコンテキストのCompositeを設定します。

31

abstract void setPaint(Paint paint)

Graphics2DコンテキストのPaint属性を設定します。

32

abstract void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)

レンダリングアルゴリズムの単一のプリファレンスの値を設定します。

33

abstract void setRenderingHints(Map<?,?> hints)

レンダリングアルゴリズムのすべての設定の値を、指定されたヒントに置き換えます。

34

abstract void setStroke(Stroke s)

Graphics2Dコンテキストのストロークを設定します。

35

abstract void setTransform(AffineTransform Tx)

Graphics2DコンテキストのTransformを上書きします。

36

abstract void shear(double shx, double shy)

現在のGraphics2D変換とせん断変換を連結します。

37

abstract void transform(AffineTransform Tx)

rulelast-specified-first-appliedに従って、このGraphics2DのTransformでAffineTransformオブジェクトを作成します。

38

abstract void translate(double tx, double ty)

現在のGraphics2D変換と変換変換を連結します。

39

abstract void translate(int x, int y)

Graphics2Dコンテキストの原点を現在の座標系のポイント(x、y)に変換します。

継承されたメソッド

このクラスは、次のクラスからメソッドを継承します。

  • java.lang.Object

Graphics2Dの例

たとえば、 D:/> AWT> com> finddevguides> gui> の任意のエディターを使用して、次のJavaプログラムを作成します。

AWTGraphicsDemo.java

package com.finddevguides.gui;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;

public class AWTGraphicsDemo extends Frame {

   public AWTGraphicsDemo(){
      super("Java AWT Examples");
      prepareGUI();
   }

   public static void main(String[] args){
      AWTGraphicsDemo  awtGraphicsDemo = new AWTGraphicsDemo();
      awtGraphicsDemo.setVisible(true);
   }

   private void prepareGUI(){
      setSize(400,400);
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent windowEvent){
            System.exit(0);
         }
      });
   }

   @Override
   public void paint(Graphics g) {
      Graphics2D g2 = (Graphics2D)g;
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
         RenderingHints.VALUE_ANTIALIAS_ON);
      Font font = new Font("Serif", Font.PLAIN, 24);
      g2.setFont(font);
      g2.drawString("Welcome to finddevguides", 50, 70);
   }
}

コマンドプロンプトを使用してプログラムをコンパイルします。 D:/> AWT に移動し、次のコマンドを入力します。

D:\AWT>javac com\finddevguides\gui\AWTGraphicsDemo.java

エラーが発生しない場合は、コンパイルが成功したことを意味します。 次のコマンドを使用してプログラムを実行します。

D:\AWT>java com.finddevguides.gui.AWTGraphicsDemo

次の出力を確認します

AWT Graphics2D