Function_GUI Class - Shir-Av/Ex1 GitHub Wiki

Functions_GUI class implements functions interface. represents a collection of functions that the usar can save from a file or read from a file and draw a graph. This class uses StdDraw library.

This object is buils of an ArrayList of type function.

Constructors and methods implemented:

  • public void initFromFile(String file): Initialize function to this object from a given file by using File class and scanner class. this method Throws IOExepction in case the file reading want wrong.

  • public void saveToFile(String file): Save the object's functions on a file by using File class and scanner class.this method ruuns on the arraylist using iterator and adds the write the cell's data to the file. Creatse new file named "string file.txt" ,this method Throws IOExepction in case the file writing want wrong.

  • public void drawFunctions(int width, int height, Range rx, Range ry, int resolution): this method Draws all the functions in the collection in a GUI window using the given the fallowing parameters for the GUI windo:

  • width - the width of the window - in pixels

  • height - the height of the window - in pixels

  • rx - the range of the horizontal axis

  • ry - the range of the vertical axis

  • resolution - the number of samples with in rx: the X_step = rx/resulution Draw the object's function on a graphic window by given parameters.

  • this function is using the Color f_color() and createCoordinateSystem(int width, int height, Range rx, Range ry).

  • private void createCoordinateSystem(int width, int height, Range rx, Range ry): this method sets the GUI canvas size, the X and Y range with the given paremeters, ans sets the "checker" page and the Number axis.

  • private Color f_color(): this method sets Random color for the function drawing.

  • public void drawFunctions(String json_file): Draw the object's functions on a graphic window by reading the parameters from a given json file. this method use Gson jar in order to read from the json file and the drawFunctions(int width, int height, Range rx, Range ry, int resolution) method in order to draw the collection and the Jsonparam.class to get the format of the json file.