Specified File Reader and Canvas Project In J2ME UoBabylon / College Of Information Technology Dep.: Information Network Stage :Third Names: 1)Bashar Hamid 2)Noor Al-Huda Hamid 3)Huda kadem 4)Noor Mohammed 5)Luma Mohammed Supervised by Mr. Alaaddin Abdul-Hassan introduction: In this project , shows you how to read the data of the specified file. To implement this type of logic we need to create a text file in the res folder of the directory. In this application we are creating a "bashar.txt" file and read the data of this file. -Classes uses in Project: java.io InputStream This abstract class is the superclass of all classes representing an input stream of bytes. Applications that need to define a subclass of InputStream must always provide a method that returns the next byte of input. Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255 . If no byte is available because the end of the stream has been reached, the value -1 is returned. If the end of the stream is detected, An exception is thrown, therefor Must be use IOException if an I/O error occurs. Reads some number of bytes from the input stream and stores them into the StringBuffer sb. The number of bytes actually read is returned as an integer. If sb is null, a null Exception is returned. - Tow Forms(form1,form2) are used and one Canvas(canvas): form1 contains commands: Read , about ,exit Form2 contain gauge only that invoked form addGauge() method with Interactive value,max value is 12 ,and 0 initialValue. Canvas: The Canvas class is a base class for writing applications that need to handle low-level events and to issue graphics calls for drawing to the display. Game applications will likely make heavy use of the Canvas class. A Canvas component represents a blank rectangular area of the screen onto which the application can draw. One of methods in canvas is void paint() method that Paints the canvas. The application must implement this method in order to paint any graphics. public void paint(Graphics g) g - the Graphics object to be used for rendering the Canvas. The Graphics object's clip region defines the area of the screen that is considered to be invalid. A correctly-written paint() routine must paint every pixel within this region. This is necessary because the implementation is not required to clear the region prior to calling paint() on it. Thus, failing to paint every pixel may result in a portion of the previous screen image remaining visible. Applications must not assume that they know the underlying source of the paint() call and use this assumption to paint only a subset of the pixels within the clip region. The reason is that this particular paint() call may have resulted from multiple repaint() requests, some of which may have been generated from outside the application. An application that paints only what it thinks is necessary to be painted may display incorrectly if the screen contents had been invalidated by, for example, an incoming telephone call. The Graphics object passed to the paint() method has the following properties: the destination is the actual display, or if double buffering is in effect, a back buffer for the display; the clip region includes at least one pixel within this Canvas; the current color is black; the font is the same as the font returned by Font.getDefaultFont(); the stroke style is SOLID; the origin of the coordinate system is located at the upper-left corner of the Canvas; and the Canvas is visible, that is, a call to isShown() will return true. Methods: - public void setColor(int red, int green, int blue): Sets the current background color to the specified RGB values. All subsequent rendering operations will use this specified color. RGB(Read,Green,Blue) - the color being set .and the range of each one from 0-255 - public void fillRect(int x, int y, int width,int height): Fills the specified rectangle with the current color. If either width or height is zero or less, nothing is drawn. Parameters: x - the x coordinate of the rectangle to be filled y - the y coordinate of the rectangle to be filled width - the width of the rectangle to be filled height - the height of the rectangle to be filled -public void drawString(String str,int x,int y,int anchor) Draws the specified String using the current font and color graphics object. The x,y position is the position of the anchor point. Parameters: str - the String to be drawn x - the x coordinate of the anchor point y - the y coordinate of the anchor point anchor - the anchor point for positioning the text (RIGHT, LEFT, TOP, BOTTOM,….) - public static Font getFont(int inp_face, int inp_style, int inp_size): Obtains an object representing a font having the specified face, style, and size. Parameters: inp_face - one of FACE_SYSTEM, FACE_MONOSPACE, or FACE_PROPORTIONAL inp_style - STYLE_PLAIN, or a combination of STYLE_BOLD, STYLE_ITALIC, and STYLE_UNDERLINED inp_size - one of SIZE_SMALL, SIZE_MEDIUM, or SIZE_LARGE -public void setFont(Font font) : Sets the font for all subsequent text rendering operations. If font is null, it is equivalent to setFont(Font.getDefaultFont()). Parameters: font - the specified font - public void drawImage(Image image, int x, int y, int anchor): Draws the specified image by using the anchor point. The image can be drawn in different positions relative to the anchor point by passing the appropriate position constants. Parameters: image - the specified image to be drawn x - the x coordinate of the anchor point y - the y coordinate of the anchor point anchor - the anchor point for positioning the image In this project canvas displayed in two times: -When start application by calling it from addcanvas() method with and set the display to canvas and using threading inside this method. -In About command when clicked it. Contents of Canvas displayable in project: -Two commands : back command(that return to the main form(read form)),exit(that exit form application). - Ticker("Welcome to project") :By calling canvas. setTicker() to display in The existence of a ticker may affect the size of the area available for Displayable's contents. - public static Image createImage(Image source): Creates an immutable image from a source image. In this project we draw the image into a Graphics object by using drawImage() method. Parameters: source - the source image. -In Read file Command ,two types of alert uses : When the specified file is found,use the alert whit title "read file", and setTimeout FOREVER to display the text in alert. When the specified file is not found ,use the alert whit title "empty", and setTimeout for 5000(5 second). References: - http://www.roseindia.net/j2me/read-file.shtml http://www.it.uc3m.es/florina/docencia/j2me/midp/docs/api/javax/microed ition/lcdui/Graphics.html - http://www.java2s.com/Open-Source/Java/6.0-JDKModules/j2me/java/io/InputStream.java.htm - http://www.ezdia.com/epad/j2me-canvas-programming-introduction/386/ - http://www.java2s.com/Tutorial/Java/0430__J2ME/PaintCanvasinathread.ht m - http://www.itcsolutions.eu/2011/07/27/j2me-tutorial-how-to-create-anddisplay-forms-and-alerts/ - http://www.roseindia.net/j2me/image-item.shtml