Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Graphics10-29-2010Opening DiscussionSolutions to the interclass problem.Do you have questions about the assignment?Minute essay comments:Could you write Sudoku or Battleship?Fixing in-class code.Courses that use GUIs.Saving changes in Pokemon.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 Pokemon on battlefield.Drawing Dinosaurs.Drawing anything there is 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 DrawingOf course, Graphics2D 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 EssayWhat are your thoughts on Scala? What do you see as its strengths and weaknesses for this course.Make sure to give me your “higher priority courses” as soon as you know them.Interclass problem:Write a script that has a custom drawn panel with something in it. Try to listen to the mouse Publisher in the panel and do something with the different
View Full Document