如何在netbeans的环境下修改java me的字体的大小和格式 20
我现在做的就是如图的效果,可是我想把“主目录”三个字的字体和大小改变小,还有可不可在这个窗口下添加个背景图片?我的现在的代码是:publicclassMenuCanvas...
我现在做的就是如图的效果,可是我想把“主目录”三个字的字体 和大小改变小,
还有可不可在这个窗口下添加个背景图片?
我的现在的代码是:
public class MenuCanvas extends Canvas {
//selected变量标记了焦点位置
private int selected = 0;
private int preferWidth = -1;
private int preferHeight = -1;
public final int[] OPTIONS = {0, 1, 2, 3, 4};
public final String[] LABELS = {"新游戏", "继续游戏", "设置", "排名", "帮助"};
private gameCanv gc;
private Display dp;
public MenuCanvas() {
selected = OPTIONS[0];
//计算菜单选项的长度和高度值
Font f = Font.getDefaultFont();
for (int i = 0; i < LABELS.length; i++) {
int temp = f.stringWidth(LABELS[i]);
if (temp > preferWidth) {
preferWidth = temp;
}
}
preferWidth = preferWidth + 2 * 8;
preferHeight = f.getHeight() + 2 * 4;
}
public void paint(Graphics g) {
//清除屏幕
int color = g.getColor();
g.setColor(0x68f4a3);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(color);
//设定一个主菜单项
g.drawString("主菜单", getWidth()/2, 20, Graphics.HCENTER|Graphics.TOP);
g.setColor(0xffffff);
g.fillRect(0, 50, getWidth(), 3);
//计算整个菜单的高度,宽度和(x,y)
int rectWidth = preferWidth;
int rectHeight = preferHeight * LABELS.length;
int x = (getWidth() - rectWidth) / 2;
int y = (getHeight() - rectHeight) /2;
//画矩形8
g.drawRect(x, y, rectWidth, rectHeight);
for (int i = 1; i < LABELS.length; i++) {
g.drawLine(x, y + preferHeight * i, x + rectWidth, y + preferHeight * i);
}
//画菜单选项,并根据selected的值判断焦点
for (int j = 0; j < LABELS.length; j++) {
if (selected == j) {
g.setColor(0x73b442);
g.fillRect(x + 1, y + j * preferHeight + 1, rectWidth - 1, preferHeight - 1);
g.setColor(color);
}
g.drawString(LABELS[j], x + 8, y + j * preferHeight + 4, Graphics.LEFT | Graphics.TOP);
}
}
我给如何修改? 展开
还有可不可在这个窗口下添加个背景图片?
我的现在的代码是:
public class MenuCanvas extends Canvas {
//selected变量标记了焦点位置
private int selected = 0;
private int preferWidth = -1;
private int preferHeight = -1;
public final int[] OPTIONS = {0, 1, 2, 3, 4};
public final String[] LABELS = {"新游戏", "继续游戏", "设置", "排名", "帮助"};
private gameCanv gc;
private Display dp;
public MenuCanvas() {
selected = OPTIONS[0];
//计算菜单选项的长度和高度值
Font f = Font.getDefaultFont();
for (int i = 0; i < LABELS.length; i++) {
int temp = f.stringWidth(LABELS[i]);
if (temp > preferWidth) {
preferWidth = temp;
}
}
preferWidth = preferWidth + 2 * 8;
preferHeight = f.getHeight() + 2 * 4;
}
public void paint(Graphics g) {
//清除屏幕
int color = g.getColor();
g.setColor(0x68f4a3);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(color);
//设定一个主菜单项
g.drawString("主菜单", getWidth()/2, 20, Graphics.HCENTER|Graphics.TOP);
g.setColor(0xffffff);
g.fillRect(0, 50, getWidth(), 3);
//计算整个菜单的高度,宽度和(x,y)
int rectWidth = preferWidth;
int rectHeight = preferHeight * LABELS.length;
int x = (getWidth() - rectWidth) / 2;
int y = (getHeight() - rectHeight) /2;
//画矩形8
g.drawRect(x, y, rectWidth, rectHeight);
for (int i = 1; i < LABELS.length; i++) {
g.drawLine(x, y + preferHeight * i, x + rectWidth, y + preferHeight * i);
}
//画菜单选项,并根据selected的值判断焦点
for (int j = 0; j < LABELS.length; j++) {
if (selected == j) {
g.setColor(0x73b442);
g.fillRect(x + 1, y + j * preferHeight + 1, rectWidth - 1, preferHeight - 1);
g.setColor(color);
}
g.drawString(LABELS[j], x + 8, y + j * preferHeight + 4, Graphics.LEFT | Graphics.TOP);
}
}
我给如何修改? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询