⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphics.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * <P>Constant for positioning the anchor point of text and images     * above the text or image.</P>     *     * <P>Value 16 is assigned to TOP.</P>     */    public static final int TOP = 16;    /**     * <P>Constant for positioning the anchor point of text and images     * below the text or image.</P>     *     * <P>Value 32 is assigned to BOTTOM.</P>     */    public static final int BOTTOM = 32;    /**     * <P>Constant for positioning the anchor point at the baseline of text.</P>     *     * <P>Value 64 is assigned to BASELINE.</P>     */    public static final int BASELINE = 64;    /**     * <P>Constant for the SOLID stroke style.</P>     *     * <P>Value 0 is assigned to SOLID.</P>     */    public static final int SOLID = 0;    /**     * <P>Constant for the DOTTED stroke style.</P>     *     * <P>Value 1 is assigned to DOTTED.</P>     */    public static final int DOTTED = 1;    /**     * Intialize the native peer of this Graphics context     */    private native void init();    /**     * Create a Graphics object with the given width and height     *     * @param w The maximum width of the new Graphics object     * @param h The maximum height of the new Graphics object     */    Graphics(int w, int h) {        destination = null;        maxWidth  = w;        maxHeight = h;        init();        reset();    }    /**     * Retrieve the Graphics context for the given Image     *     * @param img The Image to get a Graphics context for     * @return Graphics Will return a new ImageGraphics object if     *                  the Image is non-null, otherwise will return     *                  a new Graphics object with Display.WIDTH     *                  maximum width and Display.HEIGHT maximum     *                  height     */    static Graphics getGraphics(Image img) {        if (img == null) {            return new Graphics(Display.WIDTH, Display.HEIGHT);        } else {            return new ImageGraphics(img);        }    }    /**     * Translates the origin of the graphics context to the point     * (x, y) in the current coordinate system. All coordinates     * used in subsequent rendering operations on this graphics     * context will be relative to this new origin.<p>     *     * The effect of calls to translate() are cumulative. For example, calling     * translate(1, 2) and then translate(3, 4) results in a translation of     * (4, 6). <p>     *     * The application can set an absolute origin (ax, ay) using the following     * technique:<p>     * <code>     * g.translate(ax - g.getTranslateX(), ay - g.getTranslateY())     * </code><p>     *     * @param x the x coordinate of the new translation origin     * @param y the y coordinate of the new translation origin     * @see #getTranslateX()     * @see #getTranslateY()     */    public void translate(int x, int y) {        transX += x;        transY += y;    }    /**     * Gets the X coordinate of the translated origin of this graphics context.     * @return X of current origin     */    public int getTranslateX() {        return transX;    }    /**     * Gets the Y coordinate of the translated origin of this graphics context.     * @return Y of current origin     */    public int getTranslateY() {        return transY;    }    /**     * Gets the current color.     * @return an integer in form 0x00RRGGBB     * @see #setColor(int, int, int)     */    public int getColor() {        return rgbColor;    }    /**     * Gets the red component of the current color.     * @return integer value in range 0-255     * @see #setColor(int, int, int)     */    public int getRedComponent() {        return (rgbColor >> 16) & 0xff;    }    /**     * Gets the green component of the current color.     * @return integer value in range 0-255     * @see #setColor(int, int, int)     */    public int getGreenComponent() {        return (rgbColor >> 8) & 0xff;    }    /**     * Gets the blue component of the current color.     * @return integer value in range 0-255     * @see #setColor(int, int, int)     */    public int getBlueComponent() {        return rgbColor & 0xff;    }    /**     * Gets the current grayscale value of the color being used for rendering     * operations. If the color was set by setGrayScale(), that value is simply     * returned. If the color was set by one of the methods that allows setting     * of the red, green, and blue components, the value returned is      * computed from     * the RGB color components (possibly in a device-specific fashion)      * that best     * approximates the brightness of that color.     *     * @return integer value in range 0-255     *      * @see #setGrayScale     */    public int getGrayScale() {        return gray;    }    /**     * Get a gray value given the RGB values     *     * @param red The Red pixel value     * @param green The Green pixel value     * @param blue The Blue pixel value     * @return int The grayscale value corresponding to the RGB color     */    private static int grayVal(int red, int green, int blue) {        /* CCIR Rec 601 luma (nonlinear rgb to nonlinear "gray") */        return (red*76 + green*150 + blue*29) >> 8;    }    /**     * Get a specific pixel value     *     * @param rgb     * @param gray     * @param isGray     * @return int     */    private native int getPixel(int rgb, int gray, boolean isGray);    /**     * Sets the current color to the specified RGB values. All subsequent     * rendering operations will use this specified color.     * @param red The red component of the color being set in range 0-255.     * @param green The green component of the color being set in range 0-255.     * @param blue The blue component of the color being set in range 0-255.     * @throws IllegalArgumentException if any of the color components     * are outside of range 0-255.     *     * @see #getColor     */    public void setColor(int red, int green, int blue) {        if ((red < 0)   || (red > 255)             || (green < 0) || (green > 255)            || (blue < 0)  || (blue > 255)) {            throw new IllegalArgumentException("Value out of range");        }        rgbColor = (red << 16) | (green << 8) | blue;        gray = grayVal(red, green, blue);        pixel = getPixel(rgbColor, gray, false);    }    /**     * Sets the current color to the specified RGB values. All subsequent     * rendering operations will use this specified color. The RGB value     * passed in is interpreted with the least significant eight bits     * giving the blue component, the next eight more significant bits     * giving the green component, and the next eight more significant     * bits giving the red component. That is to say, the color component     * is specified in the form of 0x00RRGGBB. The high order byte of this value     * is ignored.     *     * @param RGB the color being set     *     * @see #getColor     */    public void setColor(int RGB) {        int red   = (RGB >> 16) & 0xff;        int green = (RGB >> 8)  & 0xff;        int blue  = (RGB)  & 0xff;        rgbColor = RGB & 0x00ffffff;        gray = grayVal(red, green, blue);        pixel = getPixel(rgbColor, gray, false);    }    /**     * Sets the current grayscale to be used for all subsequent     * rendering operations. For monochrome displays, the behavior     * is clear. For color displays, this sets the color for all     * subsequent drawing operations to be a gray color equivalent     * to the value passed in. The value must be in the range 0-255.     * @param value the desired grayscale value     * @throws IllegalArgumentException if the gray value is out of range     *     * @see #getGrayScale     */    public void setGrayScale(int value) {        if ((value < 0) || (value > 255)) {            throw new IllegalArgumentException("Gray value out of range");        }        rgbColor = (value << 16) | (value << 8) | value;        gray = value;        pixel = getPixel(rgbColor, gray, true);    }    /**     * Gets the current font.     * @return current font     * @see javax.microedition.lcdui.Font     * @see #setFont(javax.microedition.lcdui.Font)     */    public Font getFont() {        return currentFont;    }    /**     * Sets the stroke style used for drawing lines, arcs, rectangles, and      * rounded rectangles.  This does not affect fill, text, and image      * operations.     * @param style can be SOLID or DOTTED     * @throws IllegalArgumentException if the style is illegal     *     * @see #getStrokeStyle     */    public void setStrokeStyle(int style) {        if ((style != SOLID) && (style != DOTTED)) {            throw new IllegalArgumentException("Invalid line style");        }        this.style = style;    }    /**     * Gets the stroke style used for drawing operations.     * @return stroke style, SOLID or DOTTED     *     * @see #setStrokeStyle     */    public int getStrokeStyle() {        return style;    }    /**     * Sets the font for all subsequent text rendering operations.  If font is      * null, it is equivalent to     * <code>setFont(Font.getDefaultFont())</code>.     *      * @param font the specified font     * @see javax.microedition.lcdui.Font     * @see #getFont()     * @see #drawString(java.lang.String, int, int, int)     * @see #drawChars(char[], int, int, int, int, int)     */    public void setFont(Font font) {        currentFont = (font == null) ? Font.getDefaultFont() : font;    }     /**     * Gets the X offset of the current clipping area, relative     * to the coordinate system origin of this graphics context.     * Separating the getClip operation into two methods returning     * integers is more performance and memory efficient than one     * getClip() call returning an object.     * @return X offset of the current clipping area     * @see #clipRect(int, int, int, int)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -