JAVA2D Thai

  • View
    1.242

  • Download
    6

Embed Size (px)

DESCRIPTION

JAVA2D program command and example.เรียนรู้ จาวา ด้วยตนเอง กับ java2d.ภาษาไทย

Text of JAVA2D Thai

11 Java 2D JFC (Java Foundation Class) Java 2 2 1. 2. 3. 4. 5. 6. 7. PRINTERJava 2D java.awt.Graphics2D Graphics java method : paint ,paintAll ,update ,print, printAll,getGraphicspublic void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; ...} X Y(1-1) X Y 2 java Swing java AWT packet Java 2D Package java.awt java.awt.geom java.awt.font java.awt.color java.awt.image java.awt.image.renderable java.awt.print java.awt class interface AlphaComposite BasicStroke ColorComposite CompositeContext FontGradientPaint Graphics2D GraphicsConfigurationGraphicsDevice GraphicsEnvironment PaintPaintContext Rectangle ShapeStroke TexturePaint Transparency java.awt.geom class interface AffineTransform Arc2D Arc2D.DoubleArc2D.Float Area CubicCurve2DCubicCurve2D.Double CubicCurve2D.Float Dimension2DEllipse2D Ellipse2D.Double Ellipse2D.FloatFlatteningPathIterator GeneralPath Line2DLine2D.Double Line2D.Float PathIteratorPoint2D Point2D.Double Point2D.FloatQuadCurve2D QuadCurve2D.Double QuadCurve2D.FloatRectangle2D Rectangle2D.Double Rectangle2D.FloatRectangularShape RoundRectangle2D RoundRectangle2D.DoubleRoundRectangle2D.Float java.awt.font class interface 3FontRenderContext GlyphJustificationInfo GlyphMetricsGlyphVector GraphicAttribute ImageGraphicAttributeLineBreakMeasurer LineMetrics MultipleMasterOpenType ShapeGrapicAttribute TextAttributeTextHitInfo TextLayout TransformAttribute java.awt.color class interface ColorSpace ICC_ColorSpace ICC_ProfileICC_ProfileGray ICC_ProfileRGB java.awt.image java.awt.image.renderable package class interface AffineTransformOp BandCombineOp BandedSampleModelBufferedImage BufferedImageFilter BufferedImageOpByteLookupTable ColorConvertOp ColorModelComponentColorModel ComponentSampleModel ConvolveOpContextualRenderedImageFactory DataBufferDataBufferByte DataBufferInt DataBufferShortDataBufferUShort DirectColorModel IndexColorModelKernel LookupOp LookupTableMultiPixelPackedSampleModel PackedColorModel ParameterBlockPixelInterleavedSampleModel Raster RasterOpRenderableImage RenderableImageOp RenderableImageProducerRenderContext RenderedImageFactory RenderedImageRescaleOp SampleModel ShortLookupTableSinglePixelPackedSampleModel TileObserverWritableRaster WritableRenderedImage java.awt.print classe interface Java 2DBook Pageable PageFormat 4Paper Printable PrinterGraphicsPrinterJob java 2D fill(), draw(), drawString() drawImage() method Graphics2D - instances class (shape) render fill() draw() fill() draw() - (text) Strings array chars render drawString()- instances (image) render drawImage() 5 2 Class java.awt.geom.*; java.awt.*; Points2D Java2D package java.awt.geom Point2D user space x y point pixel point pixel Points pixel rendering Points2D abstract class Points2D Points2D.Float Points2D.Double static inner Points2D (precision) Point java.awt integer Points2D.Float float Double Points2D.Double constructors public Point2D.Double( ):public Point2D.Double(double x, double y);public Point2D.Float( );public Point2D.Float(float x, float y); x y Points2DMethod Point2D methods instance public static double distance(double X1, double Y1, double X2, double Y2);public double distance(Point2D pt); 6BasicStroke Class : java.awt.BasicStroke ;BasicStroke(); BasicStroke BasicStroke(float width) ; BasicStrokeBasicStroke(float width, int cap, int join) ; BasicStroke BasicStroke(float width, int cap, int join, float miterlimit) ; BasicStroke BasicStroke(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase) ; BasicStroke BasicStroke BasicStroke( float width, int cap , int join, float miterlimit, float[] dash, float dash_phase)width cap (2-1) 7join (2-2) miterlimit dash new float[]{0,6,0,6}dash_phase offset BasicStroke dotted = new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, new float[]{0,6,0,6}, 0);g2.setStroke(dotted);g2.drawRect(3,3,w-6,h-6); BasicStroke dotted dotted g2 w-6,h-6 3,3 g2.drawLine(x1, y1, x2, y2); x1,y1 x2,y2(2-3) 8 Lind2D Class : java.awt.geom.*; , Class 2 Class Lind2D.Double Lind2D.FloatLine2D.Double(double X1, double Y1, double X2, double Y2) Line2D double.Line2D.Double (Point2D p1, Point2D p2) Point2DLine2D.Float(float X1, float Y1, float X2, float Y2) Line2D floatLine2D.Float(Point2D p1, Point2D p2) Point2DMethodpublic void setLine(double X1, double Y1, double X2, double Y2) Method double.public void setLine(float X1, float Y1, float X2, float Y2) Method float Line2D Line2D.Double(double X1, double Y1, double X2, double Y2)X1, Y1 double.X2, Y2 double.Line2D.Float(float X1, float Y1, float X2, float Y2)X1, Y1 floatX2, Y2 float 9Line2D.Double (Point2D p1, Point2D p2) Line2D.Float(Point2D p1, Point2D p2)p1, p2 public void setLine(double X1, double Y1, double X2, double Y2) public void setLine(float X1, float Y1, float X2, float Y2) Method Instance X1, Y1 X2, Y2 .Line2D.Double line = new Line2D.Double(0.0,0.0,5.5,10.0);g2.draw(line);. Instance Class Line2D.Double line x = 0.0 y = 0.0 x = 5.5 y = 10.0 Background g2 double 17E308 1.7E308 257.34 float 34E38 3.4E38 1.8f 10QuadCurve2D package java.awt.geom QuadCurve2D abstract class implements Shape quadCurve2D parametic curve draw( ) Graphics2D quadCurve2D.float quadCurve2D.Double static inner classes QuadCurve2D public QuadCurve2D.Float();public QuadCurve2D.Float(float x1, float y1, float ctrlx, float ctrly, float x2, float y2);public QuadCurve2D.Double();public QuadCurve2D.Double(double x1, double y1, double ctrlx, double ctrly, double x2, double y2); empty constructors setCurve ( ) constructors empty point 1 control point point 2 (2-4) Quadcurved2D 11CubicCurve2D package java.awt.geom CubicCurve2D abstract class implements Shape cubic paramentric curve ( y=ax2+bx2+cx2+cx2+d) draw() Graphics2D CubicCurve2D constructors public CubicCurve2D. Float () ;public CubicCurve 2D. Float (float x1, float y1, float ctrlx1, float ctrly1, float ctrlx2, float ctrly2, float x2, float y2);public CubicCurve 2D. Double () :public CubicCurve2D.Double (double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2);(2-5) CubicCurve2D 12RectangularShape and Rectangle2D package java.awt.geom RectangularShape abstract class implements Shape Rectangle2D Rectangle2D.Float Rectangle2D.Double static inner classes Rectangle2D constructors public Rectangle2D.Float ( ) ;public Rectangle2D.Float (float x, float y, float w, float h) ;public Rectangle2D.Double() ;public Rectangle2D.Double(double x, double y, double w, double h) ;(2-6) Rectangle2D.Double 13RoundRectangle2D package java.awt.geom RoundRectangle2D abstract class RectangularSharpe RoundRectangle2D RoundRectangle2D.Float RoundRectangle2D.Double static inner classes float doublepublic RoundRectang2D.Float () ;public RoundRectangle2D.Float (float x, float y, float w, float h, float arcw, float arch) ;public RoundRectang2D.Double() ;public RoundRectang2D.Double(float x, float y, float w, float h, float arcw, float arch);(2-7) RoundRectangle2D.Double 14Ellipse2D package java.awt.geom Ellipse2D abstract class RectangularShape Ellipse2D Ellipse2D.Float Ellipse2D.Double static inner classes float doublepublic Ellipse2D.Float() :public Ellipse2D.Float(float x, float y, float w, float h) :public Ellipse2D.Double() :public Ellipse2D.Double(double x, double y, double w, double h) : x, y w h empty constructors x, y, w h (2-8) Ellipse2D.Double 15Arc2D package java.awt.geom Arc2D abstract class RectangularShape Arc2D Arc2D.Float Arc2D.Double static inner classes float doublepublic Arc2D.Float() ;public Arc2D.Float(int type) ;public Arc2D.Float(float x, float y, float w, float h, floatstart, float extent, int type) ;public Arc2D.Float(Rectangle2D bound, floatstart, float extent, int type) ;public Arc2D.Double() ;public Arc2D.Double(int type) ;public Arc2D.Double(double x, double y, double w, double h, double start, double extent, int type) ;public Arc2D.Double(Rectangle2D bound, double start, double extent, int type) ; x, y w h x, y, w h Rectangle2D bound start extent degree 3:00 extent extent int type Arc2Dpublic static final int OPEN ;public static final int CHORD ;public static final int PIE ; 16(2-9) Arc2D.FloatGeneralPath GeneralPath implements Shape GeneralPath package java.awt.geompublic GeneralPath () ;public GeneralPath (int rule) ;public GeneralPath (int rule, int initialCapacity) ;rule winding rule WIND_EVEN_ODD WINE_NON_ZERO initialCapacity initial capacity coordinates general path coordinates segments array initial capacity 17Method general path public void moveTo(float x,float y);public void lineTo(float x, float y);public void quadTo(float x1, float y1,float x2,float y2);public void curveTo(float x1,float y1,float x2,float y2, float x3, float y3);public void closePath(); GeneralPath eiffel = new GeneralPath();Eiffel.moveTo(20f,0f);Eiffel.lineTo(30f,0f);Eiffel.quadTo(30f,30f,50f,60f);Eiffel.lineTo(35f,60f);Eiffel.cuveTo(35f,40f,15f,40f,15f,60f);Eiffel.line