Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Graphics10-28-2011Opening DiscussionMinute essay comments:Can't type as fast as me in vi.Deciding between panels.Retails of publisher/reactor model.Coding of graphics intensive games.Sorting the in-class code by date.What is my take on Anonymous.Adding to our GUII want to make the GUIs we wrote last time put data into the tables before we move forward today.MotivationYou can do lots of things with the standard GUI elements in Swing.We could set up quite a bit of a GUI using that. However, no GUI library can predict everything that you will want to do and we want to be able to add custom drawing to our applications.Uses:Drawing a shot-chart in basketball.Drawing Dinosaurs.Drawing anything there isn't a GUI component for.Graphics in Scala/JavaFor this we will rely on the Java2D library. Java2D was added about the same time Swing was and it is fundamentally based on the java.awt.Graphics2D class.Let's go find the Java API and find this class in it.Making Custom Drawn ComponentsWe are going to follow a simple approach to doing this making a new Panel that draws what we want.new Panel {override def paint(g:Graphics2D) {...}}Whatever you draw to g appears in the panel.Capabilities of Java2DLet's look a bit at the Graphics2D class to see what some of the possibilities might be for what we can draw.The java.awt.geom package and the java.awt.image package also have some useful things in them.SettingsThere are several things that we can set on the Graphics2D object that are used when we draw things. Here are some:Paint – could be a color, but there are also gradients and texturesStroke – determines how lines are drawnFont – how you want text to appearTransform – AffineTransform allows translate, rotate, scale, or shearLess Used SettingsComposite – how colors combine when you draw over old stuffClip – where your drawings will appearRender hints – other things like antialiasingMore General DrawingGraphics2D objects aren't limited to just drawing on components.The Image class (and it's subtype BufferedImage) will let you get Graphics objects that you can draw to and what you draw will be on the image.We'll typically do this even if we are drawing to a component to implement buffering which reduces flicker.Loading ImagesThe easiest way to load images from disk is using javax.imageio.ImageIO.This class has read methods that take File or URL objects.Minute EssayHow do you think we would go about creating
View Full Document