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

📄 dialogue.java

📁 j2me手机游戏引擎,mdlet1.0
💻 JAVA
字号:
package isoj2me;/** * <p>isoj2me: Character</p> * <p>Copyright: Copyright (c) 2004</p> * <p>License: Lesser GPL (http://www.gnu.org)</p> * <p>Company: <a href=http://www.mondonerd.com target="_blank">Mondonerd.com</a></p> * @author Massimo Maria Avvisati * @version 0.5 */import javax.microedition.lcdui.*;import java.util.*;public class Dialogue {        public int border = 12; //Right border...    private String characterName = "";    private String phrase = "";    private int color = 0x000000;    private int bgColor = 0xffffff;    private boolean background = false;    private int x = 0;    private int y = 0;    public int y_message_position = 0;    public int message_height = 0;    private int xSpeech = 0;    private int ySpeech = 0;    public Dialogue(String characterName, String phrase, int color) {        this.characterName = characterName;        this.phrase = phrase;        this.color = color;    }    public Dialogue(String characterName, String phrase, int x, int y, int xSpeech,            int ySpeech, int bgColor, int color) {        this.characterName = characterName;        this.phrase = phrase;        this.color = color;        this.bgColor = bgColor;        this.background = true;        this.x = x;        this.y = y;        this.xSpeech = xSpeech;        this.ySpeech = ySpeech;    }    public void draw(Graphics g, Hashtable cueImages) {        if (background) {            g.setColor(bgColor);            g.fillRect(0, 0, g.getClipWidth(), g.getClipHeight());        }        g.drawImage(isoj2me.Utility.loadImage(characterName, cueImages), x, y,                Graphics.TOP | Graphics.LEFT);        g.setColor(color);        paintMessage(g, phrase, cueImages);    }    private void paintMessage(Graphics g, String message, Hashtable cueImages) {        g.setColor(0x000000);        g.fillRect(0, isoj2me.Utility.loadImage(characterName, cueImages)                .getHeight(), g.getClipWidth(), g.getClipHeight()                - isoj2me.Utility.loadImage(characterName, cueImages)                        .getHeight());        g.setColor(bgColor);        g.fillRect(3, isoj2me.Utility.loadImage(characterName, cueImages)                .getHeight() + 3, g.getClipWidth() - 6, g.getClipHeight()                - isoj2me.Utility.loadImage(characterName, cueImages)                        .getHeight() - 6);        Font f = Font.getFont(Font.FACE_MONOSPACE, 1, Font.SIZE_SMALL);        g.setFont(f);        g.setColor(0xff0000);        g.setColor(color);        if (f.stringWidth(message) < g.getClipWidth() - border) {            g                    .drawString(                            message,                            g.getClipWidth() / 2 + xSpeech,                            isoj2me.Utility.loadImage(characterName, cueImages)                                    .getHeight()                                    + ((g.getClipHeight() - isoj2me.Utility                                            .loadImage(characterName, cueImages)                                            .getHeight()) / 2 + ySpeech),                            Graphics.BASELINE | Graphics.HCENTER);        } else {            int x_temp = 8;            int y_temp = isoj2me.Utility.loadImage(characterName, cueImages)                    .getHeight() + 20;            for (int i = 0; i < message.length(); i++) {                if ((x_temp > g.getClipWidth() - 10)                        || (message.charAt(i) + "").startsWith("$")) { //Break                                                                       // line                    y_temp = y_temp + f.getHeight();                    x_temp = 8;                }                if ((message.charAt(i) + "").startsWith("$") == false) {                    g.drawString(message.charAt(i) + "", x_temp + xSpeech,                            y_temp + y_message_position + ySpeech,                            Graphics.BASELINE | Graphics.LEFT);                    x_temp = x_temp + f.charWidth(message.charAt(i));                }            }        }    }}

⌨️ 快捷键说明

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