12-Java-2D

12-Java-2D - 2006 Marty Hall 2D Drawing J2EE Training:

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
2 J2EE Training: http://courses.coreservlets.com/ Servlets, JSP, Struts, JSF, Hibernate, AJAX, Java 5, etc. Developed and taught by well-known author and developer. At public venues or onsite at your location. © 2006 Marty Hall 2D Drawing 3 Developed and taught by well-known author and developer. At public venues or onsite at your location. © 2006 Marty Hall For live Java training, please see training courses at http://courses.coreservlets.com/. Servlets, JSP, Struts, JSF, AJAX, Java 5, etc. Taught by the author of Core Servlets and JSP , More Servlets and JSP , and this tutorial. Available at public venues, or customized versions can be held on-site at your organization.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 J2EE training: http://courses.coreservlets.com Agenda Overview Drawing Shapes Paint Styles Transparency Using Local Fonts Stroke Styles Coordinate Transformations Requesting Drawing Accuracy 5 J2EE training: http://courses.coreservlets.com AWT vs. Java 2D Drawing: Overview AWT public void paint(Graphics g) { // Set pen parameters g.setColor(someColor); g.setFont(someLimitedFont); // Draw a shape g.drawString(…); g.drawLine(…) g.drawRect(…); // outline g.fillRect(…); // solid g.drawPolygon(…); // outline g.fillPolygon(…); // solid g.drawOval(…); // outline g.fillOval(…); // solid } Java 2D public void paintComponent(Graphics g) { // Clear off-screen bitmap super.paintComponent(g); // Cast Graphics to Graphics2D Graphics2D g2d = (Graphics2D)g; // Set pen parameters g2d.setPaint(fillColorOrPattern); g2d.setStroke(penThicknessOrPattern); g2d.setComposite(someAlphaComposite); g2d.setFont(anyFont); g2d.translate(…); g2d.rotate(…); g2d.scale(…); g2d.shear(…); g2d.setTransform(someAffineTransform); // Create a Shape object SomeShape s = new SomeShape (…); // Draw shape g2d.draw(s); // outline g2d.fill(s); // solid }
Background image of page 2
6 J2EE training: http://courses.coreservlets.com Java 2D Drawing Process: Step 1 Cast Graphics object to Graphics2D public void paintComponent(Graphics g) { super.paintComponent(g); // Typical Swing Graphics2D g2d = (Graphics2D)g; g2d.doSomeStuff(. ..); ... } Note All methods that return Graphics in Java return Graphics2D in Java 2 and later paint, paintComponent getGraphics 7 J2EE training: http://courses.coreservlets.com Java 2D Drawing Process: Step 2 Set pen parameters g2d. setPaint (fillColorOrPattern); g2d. setStroke (penThicknessOrPattern); g2d. setComposite (someAlphaComposite); g2d. setFont (someFont); g2d. translate (...); g2d. rotate (...); g2d. scale (...); g2d. shear (...); g2d. setTransform (someAffineTransform);
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 J2EE training: http://courses.coreservlets.com Java 2D Drawing Process: Step 3 Create a Shape object. Rectangle2D.Double rect = . ..; Ellipse2D.Double ellipse = . ..; Polygon poly = . ..; GeneralPath path = . ..; // Satisfies Shape interface SomeShapeYouDefined shape = . ..; Note Most shapes are in the java.awt.geom package There is a corresponding Shape class for most of the draw Xxx methods of Graphics (see next slide) 9 J2EE training: http://courses.coreservlets.com Built-in Shape Classes Arc2D.Double, Arc2D.Float Area (a shape built by union, intersection, subtraction and xor of
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/16/2009 for the course CSCI 571 taught by Professor Papa during the Summer '07 term at USC.

Page1 / 26

12-Java-2D - 2006 Marty Hall 2D Drawing J2EE Training:

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online