📄 graphics.java
字号:
* @see #drawChars(char[], int, int, int, int, int) */ public native void drawString(java.lang.String str, int x, int y, int anchor); /** * Draws the specified String using the current font and color. * The x,y position is the position of the anchor point. * See <a href="#anchor">anchor points</a>. * @param str the String to be drawn * @param offset zero-based index of first character in the substring * @param len length of the substring * @param x the x coordinate of the anchor point * @param y the y coordinate of the anchor point * @param anchor the anchor point for positioning the text * @see #drawString(String, int, int, int). * @throws StringIndexOutOfBoundsException if offset and length do not * specify a valid range within the String str * @throws IllegalArgumentException if anchor is not a legal value * @throws NullPointerException if str is null */ public native void drawSubstring(String str, int offset, int len, int x, int y, int anchor); /** * Draws the specified character using the current font and color. * @param character the character to be drawn * @param x the x coordinate of the anchor point * @param y the y coordinate of the anchor point * @param anchor the anchor point for positioning the text; see * <a href="#anchor">anchor points</a> * * a valid range within the data array * @throws IllegalArgumentException if anchor is not a legal value * * @see #drawString(java.lang.String, int, int, int) * @see #drawChars(char[], int, int, int, int, int) */ public native void drawChar(char character, int x, int y, int anchor); /** * Draws the specified characters using the current font and color. * @param data the array of characters to be drawn * @param offset the start offset in the data * @param length the number of characters to be drawn * @param x the x coordinate of the anchor point * @param y the y coordinate of the anchor point * @param anchor the anchor point for positioning the text; see * <a href="#anchor">anchor points</a> * * @throws ArrayIndexOutOfBoundsException if offset and length do not * specify a valid range within the data array * @throws IllegalArgumentException if anchor is not a legal value * @throws NullPointerException if data is null * * @see #drawString(java.lang.String, int, int, int) */ public native void drawChars(char[] data, int offset, int length, 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. * See <a href="#anchor">anchor points</a>. * @param img the specified image to be drawn * @param x the x coordinate of the anchor point * @param y the y coordinate of the anchor point * @param anchor the anchor point for positioning the image * @throws IllegalArgumentException if anchor is not a legal value * @throws NullPointerException if img is null * @see Image */ public native void drawImage(Image img, int x, int y, int anchor); // private implementation // /** Translated x,y coordinates */ private int transX, transY; /** Array to hold the clip values */ private short clip[] = new short[4]; /* format is -- x y w h */ /** A flag indicating the clipping state */ private boolean clipped = false; /** Clip coordinates */ private int clipX2, clipY2; /** Pixel values */ private int rgbColor, gray, pixel; /** Line stroke style */ private int style; // line stroke style /** The current Font */ private Font currentFont; /** The maximum width and height */ private int maxWidth, maxHeight; /** The 'destination' Image to paint to */ Image destination; /** * Reset this Graphics context with the given coordinates * * @param x1 The upper left x coordinate * @param y1 The upper left y coordinate * @param x2 The lower right x coordinate * @param y2 The lower right y coordinate */ void reset(int x1, int y1, int x2, int y2) { transX = transY = 0; short clipX1 = (x1 > 0) ? ((short) (x1 & 0x7fff)) : 0; short clipY1 = (y1 > 0) ? ((short) (y1 & 0x7fff)) : 0; clipX2 = x2; clipY2 = y2; clip[0] = clipX1; clip[1] = clipY1; clip[2] = (short) (clipX2 - clipX1); clip[3] = (short) (clipY2 - clipY1); if (clip[2] < 0) { clip[2] = 0; } if (clip[3] < 0) { clip[3] = 0; } if ((clipX1 > 0) || (clipY1 > 0) || (clipX2 < maxWidth) || (clipY2 < maxHeight)) { clipped = true; } else { clipped = false; } currentFont = Font.getDefaultFont(); style = SOLID; rgbColor = gray = 0; pixel = getPixel(rgbColor, gray, true); } /** * Reset this Graphics context to its default dimensions * (same as reset(0, 0, maxWidth, maxHeight) */ void reset() { reset(0, 0, maxWidth, maxHeight); }}/** * <p>SYNC NOTE: Unlike the Graphics class, multiple threads may issue calls * on ImageGraphics instances at any time. It is therefore the responsibility * of the ImageGraphics class to ensure that all public methods are MT-safe. * </p> * * <p>Some methods are implicitly safe already, namely those that are native * methods and those that make a single atomic access to instance state. * Those method implementations are simply inherited from the superclass. The * inherited methods are included below, within comments, to indicate this * fact. If the superclass' implementation of a method changes, this class * may need to override it and provide locking. </p> * * <p>Any method that has multiple accesses to shared state must be protected * with a synchronized block. As for the Graphics class, all access is to the * state of this instance, and so locking is done on 'this' instead of on * Display.LCDUILock.</p> */class ImageGraphics extends Graphics { /** * Constuct a new ImageGraphics * * @param img The Image to use to construct the ImageGraphics */ ImageGraphics(Image img) { super(img.getWidth(), img.getHeight()); destination = img; } /** * Translate this Graphics context by the given offset * * @param x The x coordinate offset * @param y The y coordinate offset */ public void translate(int x, int y) { synchronized (this) { super.translate(x, y); } } /** * Set the Color of this Graphics context * * @param red The Red color component * @param green The Green color component * @param blue The Blue color component */ public void setColor(int red, int green, int blue) { synchronized (this) { super.setColor(red, green, blue); } } /** * Set the Color of this Graphics context * * @param RGB The RGB composite color value */ public void setColor(int RGB) { synchronized (this) { super.setColor(RGB); } } /** * Set the gray scale value of this Graphics context * * @param value The gray scale value */ public void setGrayScale(int value) { synchronized (this) { super.setGrayScale(value); } } /** * Get the x coordinate of the clip * * @return int The x coordinate of the clip */ public int getClipX() { synchronized (this) { return super.getClipX(); } } /** * Get the y coordinate of the clip * * @return int The y coordinate of the clip */ public int getClipY() { synchronized (this) { return super.getClipY(); } } // SYNC NOTE: the superclass implementations of getClipWidth() and // getClipHeight() read a single value atomically, so no locking is // necessary. We simply inherit the implementations from the superclass. // public int getClipWidth(); // public int getClipHeight(); /** * Add the clip rectangle of this Graphics context * * @param x The x coordinate of the rectangle * @param y The y coordinate of the rectangle * @param w The width of the rectangle * @param h The height of the rectangle */ public void clipRect(int x, int y, int w, int h) { synchronized (this) { super.clipRect(x, y, w, h); } } /** * Set the clip of this Graphics context * * @param x The x coordinate of the clip * @param y The y coordinate of the clip * @param w The width of the clip * @param h The height of the clip */ public void setClip(int x, int y, int w, int h) { synchronized (this) { super.setClip(x, y, w, h); } } // SYNC NOTE: all of the following are native methods, which run // atomically, so no synchronization is necessary. We therefore simply // inherit them from the superclass. // public native void drawLine(int x1, int y1, int x2, int y2); // public native void fillRect(int x, int y, int width, int height); // public native void drawRect(int x, int y, int width, int height); // public native void drawRoundRect(int x, int y, int width, int height, // int arcWidth, int arcHeight); // public native void fillRoundRect(int x, int y, int width, int height, // int arcWidth, int arcHeight); // public native void fillArc(int x, int y, int width, int height, // int startAngle, int arcAngle); // public native void drawArc(int x, int y, int width, int height, // int startAngle, int arcAngle); // public native void drawString(java.lang.String str, // int x, int y, int anchor); // public native void drawSubstring(String str, int offset, int len, // int x, int y, int anchor); // public native void drawChar(char character, int x, int y, int anchor); // public native void drawChars(char[] data, int offset, int length, // int x, int y, int anchor); // public native void drawImage(Image img, int x, int y, int anchor);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -