[SOLVED] java gui

$25

File Name: java_gui.zip
File Size: 75.36 KB

5/5 - (1 vote)

You will build one or more UI-based mini-applications that displays and manipulate ObservableFrame2D objects. These little mini-applications are simple enough that they dont really require the use of a model-view-controller pattern and can be encapsulated easily into a single self-contained UI widget. In order to display ObservableFrame2D objects on to the screen, we need to make use of some built-in Java library classes for images. In order to shield you from the details of these classes, I have created a subclass of the Java Canvas type called FrameView that is capable of displaying an ObservableFrame2D which you should use in your solutions. You dont really need to understand how it works internally to use it, but in order to support this object, we need a few supporting functions.

  • The Frame2D interface now includes a createObservable() method
  • This method basically converts a Frame2D object into an ObservableFrame2D object. It is implemented in AnyFrame2D which means that all of our Frame2D implementations automatically inherit this capability.
  • The ObservableFrame2D interface has been streamlined.
  • Specifically, I have removed the methods to unregister observers by region and to find observers by region. Also, an overloaded version of the registration method has been added that simply takes the observer and assumes that you are interested in the entire frame (i.e., it simply calls the original registration method with a region of interest that covers the whole frame).
  • A helper class called A7Helper has been added.
  • class method
  • This class contains three static methods that are needed to support our new FrameView class. These methods are:
    • public static Frame2D readFromURL(String url)
    • This function takes a URL string (i.e., a web address) for a picture and, if successful, constructs a Frame2D object that represents the picture. It may throw an IOException if something goes wrong.
    • methodFrame2D object
    • public static int pixelToRGB(Pixel p)
    • Javas classes for dealing with images represent pixels as integers with different bits within the integer representing the red, green, and blue components. This function converts our Pixel objects into the appropriate corresponding packed integer.
    • public static Pixel rgbToPixel(int rgb)
    • This function does the conversion between a packed RGB integer color and our Pixel representation.
    • methodspixel
  • A new class called FrameView has been added.
  • This class is a subclass of the Java Canvas user-interface component. It accepts an ObservableFrame2D object as a parameter to its constructor. A FrameView object simply paints the encapsulated ObservableFrame2D object on the screen. You can use the setFrame() method to change what ObservableFrame2D object it is painting. It implements ROIObserver and attaches itself to the ObservableFrame2D object that it encapsulates so that if the ObservableFrame2D object changes, it can repaint the picture automatically. You use it like any other user interface object (i.e., place this object into a UI container, attach listeners in order to respond to user interface events, etc.). As a subclass of Canvas, it supports all of the same event listeners that Canvas does. You will mostly just need to be able to add mouse listeners and key listeners
  • A UI widget called SimpleFrameViewWidget has been provided.
  • This widget is provided a Frame2D object and a String title as arguments to its constructor. The widget creates a user-interface comprising of a FrameView object to display the Frame2D object and a JLabel object to display the title. It also handles mouse click events on the FrameView object by printing the x and y coordinates to the console whenever a click occurs. You can use this object as a basic pattern for using FrameView in your own widgets.

The class A7SetupTest is a simple test application that creates a Frame2D object from a URL using the A7Helper.readFromURL() function, creates a new top-level user interface window with a SimpleFrameViewWidget to display the Frame2D object along with a title.

If your setup is working correctly, you shold be able to run A7SetupTest and see me appear on the screen along with the title K to the M to the P. Mouse clicks on the image should print coordinates of the click to the console.

It should look like this:

console

Follow the pattern above to create one or more of the following mini-applications. In the descriptions below, the name of the application should be the name of the main class (i.e., the one with main() to run). These are listed in the order of increasing complexity (and thus point value). For each, there may be many different ways to approach and architect your solution. We will be grading both for basic functionality as well as the design and readability of your code.

PixelInspector (5 points)

This application should load an image and when clicked display information about the pixel where the click occurs.

XY

ImageAdjuster (10 points)

This application should provide two or more sliders that adjust the image in some way. I suggest the following but you can do others if you would like:

  • Blur Replaces each pixel as the average of the pixels around it. You can think of the slider as controlling the size of a square area centered on each pixel to be averaged. So a blur size of 0 would mean no blurring. A blur size of 1 would mean averaging all adjacent pixels. A blur size of 2 would be averaging all pixels with x and y coordinates that were +/- 2 of each pixel, etc.
  • Blur 0 5 0 1 pixel pixels pixels 2 pixel 16 pixels
  • Brightness Adjusts the pixels toward black or white according to a slider. In my solution, the slider runs from -100 representing black, 0 representing the original pixel value, and 100 representing white.
  • Brightness -100 100 -100 +100
  • Saturation Adjusts the pixels toward gray scale or oversaturation. In my solution, -100 means no color and 100 means fully saturated. The formula for this is as follows: Let f be the saturation factor defined by the slider (-100 to 100). Let b be the brightness (i.e. intensity) of the original pixel. Then given a saturation factor f between -100 and 0, for each component of pixel (i.e., red, green, blue), the new value is:new = old * (1.0 + (f / 100.0) ) (b * f / 100.0)Given a saturation factor f between 0 and 100, first determine which component of the pixel is largest. Call this value l. Then calculate the following value for gain:gain = (l + ((1.0 l) * (f / 100.0))) / l;Now calculate the new value of each components as:new = old * gain
  • -100 +100 f -100 0 b pixel component (1.0 + (f / 100.0) ) (b * f / 100.0) 0100component l gain = (l + ((1.0 l) * (f / 100.0))) / l new = old * gain gaingain

My version of this mini-application looks like this:

FramePuzzle (10 points)

This application should create a 55 grid of FrameView objects that each display a portion of the original frame. The lower right corner should be replaced with a Frame2D filled with a solid color. Clicking on a row or column in line with the blank tile should move the portions over to fill the blank space, resulting in the blank space moving to where the click occured. Using the keyboard up, down, left, and right keys should swap the blank space with the adjacent portion in the appropriate direction. Getting the boundaries between the FrameView objects to line up seamlessly is very difficult (especially if the image dimensions are not a perfect multiple of 5) so dont worry if you see discontinuities.

My version of this looks like this (it is shown after Ive moved some of the pieces of the puzzle around already):

25

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] java gui
$25