1 / 11

Graphics in Java

Roger L. Norton. Graphics in Java. Our Final Project. (replace link with final project). Roger L. Norton. Roger L. Norton. Double Buffering. Draw shapes onto a hidden image. Image is copied to the required canvas when needed. Double Buffering.

callie
Download Presentation

Graphics in Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Roger L. Norton Graphics in Java Our Final Project (replace link with final project)

  2. Roger L. Norton Roger L. Norton Double Buffering Draw shapes onto a hidden image Image is copied to the required canvas when needed

  3. Double Buffering • An off-screen image (pixmap) is created, and all draw operations are done into this image. • Method update is overridden to avoid clearing the screen before paint is called. • For each step, clear the image and redraw all of the objects in the off-screen image. • In paint, the off-screen image is drawn onto the window.

  4. Double Buffering The following instructions are needed to perform double buffering: (Assume that the image will be drawn on an extension of a canvas) Declarations Dimension offScreenDimension, d; Image offScreenImage; Graphics offScreenGraphics; Constructor public MyCanvas ( ) { d = getSize(); offScreenDimension = d; offScreenImage = createImage(d.width,d.height); offScreenGraphics = offScreenImage.getGraphics(); offScreenGraphics.setColor (getForeground()); ………….. }

  5. Double Buffering method update //override update to avoid clearing the screen before calling paint publicvoid update (Graphics g) { paint (g); } method paint publicvoid paint (Graphics g) { //clear the canvas offScreenGraphics.setColor(getBackground()); offScreenGraphics.fillRect(0,0,d.width, d.height); //draw the shapes offScreenGraphics.setColor(getForeground()); for (int i = 0; i < shapeCount; i++) { s = (Shape)shapeList.elementAt(i); s.draw(offScreenGraphics); } g.drawImage(offScreenImage, 0, 0, this); }

  6. Drawing Shapes DrawRect1 (Object Model) DrawRect2 DrawOval DrawFilledOval

  7. Roger L. Norton Paint Programs DrawShapes1 DrawShapes2 DrawOval DrawFilledOval

  8. Homework #4 Create a Java Applet that implements the above GUI.

More Related