The problem of the character overlap is solved by the width function and the height function of the Font class. The next step is to stabilize the problem.
Take an example in half a year, it is also about the updated content on the background, it is not tight, it can run in MOTO I85S, but always keep prompt error, and in Motorola J2me Launchpad can't Run, there is no error in the screen. What happened? ! Later, the Motorola A388 mobile phone is running, but the softkey EXITCOMMAND cannot display correctly, and you have to exit every time. gosh……
Carefully read the source code, the general idea is to scribble the fixed content each time the MakeBackground, and this function is called in the Paint, and other write strings and other operations are called. Through hard tracking, it is found that each time the variable information will be repeatable. Looking at the help documents of Canvas, fixing the background to fix the background, actually there is no difference! sweat……
First, please annotate additional information, then declare an image, draw a fixed background information in the builder, then call DrawImage at Paint, huh, success, run in the I85S and 388 simulator . Then start drawing information on the background, display text, ok, drawing, and OK, but in DrawImage, this image is from an icon file, it should be an Immutable property. Is there a problem? ? ? ME first looked at Jar's included information, halo, actually did not include this icon file. Oh, no wonder! After selecting, compile, run, or not! Still old, look at the API DOC. Here is the documentation documentation of the PAINT function in Canvas.
Renders The Canvas. The Application Must Implement This Method in Order to Paint Any Graphics. Rendering Draw. The program must implement this method to draw graphics. 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. 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. Graphics objects shear zone designated portions of the screen, which is part of the area of the screen to Saying is invalid (that is, it is not the role of it). The correctly written Paint () method must draw each pixel in this area. The program must not think that it has been fully known where to be called, and only the partial pixels of the shear area are drawn because of this assumption. The reason is that this PAINT () call may be caused by calling repaint (), while the latter may occur outside of the program. A program that only draws some parts that need to draw, if the screen is destroyed (?), If the screen is incorporated (?), It may not be displayed normally. Operations on this graphics object after the paint () call returns are undefined. Thus, the application must not cache this Graphics object for later use or use by another thread. It must only be used within the scope of this method. Call the paint () The operation of this Grapchis object is not defined (• implementation) after the method. Therefore, it is sure to cache it to be used back to use or is called by other threads. It can only be used within the field of view of this method.
The Implementation May PostPone Visible Effects Of Graphics Operations Until The End of the Paint Method. Before the Paint () method is executed, the operation in all methods (? Implementation) will delay the visual effect of Graphics operations The Contents of the Canvas Are NEVER saved if it is hidden and then is made visible again. Thus, shortly after showNotify () is called, paint () will always be called with a Graphics object whose clip region specifies the entire displayable area of the Canvas. Applications must not rely on any contents being preserved from a previous occasion when the Canvas was current. This call to paint () will not necessarily occur before any other key, pointer, or commandAction () methods are called on the Canvas. Applications whose repaint recomputation is expensive may create An OffScreen Image, Paint Into It, And The Can Draw / this Image On The Canvas When Paint () IS CALLED. If you are hidden and then redisplay, all content of Canvas will not be saved. Therefore, after calling the showNotify () method, the Graphics object always calls the PAINT () method. The clipping zone of the Graphics object specifies all of the area where Canvas can display. When Canvas becomes the current screen, the program must not rely on the content displayed on the CANVAS on the last appearance, and this time the call to Paint () does not need to appear before any key, touch pen, or commandAction () before being called by the Canvas. Repaint Rehabilulus costs The program can create a non-current display image, draw the content on top, and then call DrawImage in the canvas's Paint () method to display. The Application Code Must Never Call Paint (); IT IS Called Only By The Implementation. The program code will never call Paint (); it can only be called by other implementation (?).
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 the Canvas is visible, that is, a call to Isshown () WILL RETURN TRUE GRAPHICS objects pass to the Paint () method must have the following properties: The target is actually displayed, if supported by the double buffer, can be used for displaying the background buffer clipping area to contain a pixel of current Canvas The current color is a black font and a font returned by font.getdefaultfont () is a Solid coordinate origin in the upper left corner of Canvas. It is also visible, that is, call isshow () should return true value, although not found Directly solve the content of the problem, but it is also a harvest, for example, in Paint (), you need to redraw over the canvas. Continue to debug, use try catch to contain the problem's DrawImage, oh, can run, but still stop a bunch of errors, check the API DOCS, there are two possibilities that may be an IllegaLaRgumentexception (if Anchor is not a LEGAL VALUE, another is a NullPointRexception (if img is null), which is famous. Haha, it is definitely an anchor problem, because ME has tested IMG in advance, ensuring it is correct. Look at what is the anchor point, that sentence is this: g.drawimage (img, width / 2, height / 2-20, g.baseline | g.hcenter); Huo Hu, pass the information, the original image does not support Baseline anchor! Also, it doesn't want Text, there is a baseline, and if you want to be positioned to use vCenter. Continue regression theme.
The flash is flashed through the background, then solve the way in the painImage in Paint (), the effect is ideal, huh, huh, finally got it. However, when testing is tested on the machine? Come out, it may be that the fonts on the Motorola A388 do not have big bar supported on the simulator on the computer. Forget it, too sleepy, I feel it ...