📄 font_attribute_form.java
字号:
package ch10;
import javax.microedition.lcdui.*;
//该类实现用户对字体属性的选择
public class Font_Attribute_Form
extends Form
implements ItemStateListener {
//声明一个代表字体外观的int型属性变量
int face;
//声明一个代表字体样式的int型属性变量
int style;
//声明一个代表字体尺寸的int型属性变量
int size;
//声明一个代表字体外观选择组对象
ChoiceGroup faceChoice;
//声明一个代表字体样式选择组对象
ChoiceGroup styleChoice;
//声明一个代表字体尺寸选择组对象
ChoiceGroup sizeChoice;
/*
3.构造器
*/
public Font_Attribute_Form() {
//设置窗体标题
super("设置属性");
faceChoice = new ChoiceGroup("外观", Choice.EXCLUSIVE);
faceChoice.append("System字体", null);
faceChoice.append("Monospace字体", null);
faceChoice.append("Proportional字体", null);
styleChoice = new ChoiceGroup("样式", Choice.MULTIPLE);
styleChoice.append("黑体", null);
styleChoice.append("斜体", null);
styleChoice.append("下划线", null);
sizeChoice = new ChoiceGroup("尺寸", Choice.EXCLUSIVE);
sizeChoice.append("小字体", null);
sizeChoice.append("中字体", null);
sizeChoice.append("大字体", null);
append(faceChoice);
append(styleChoice);
append(sizeChoice);
setItemStateListener(this);
}
//设置字体外观属性值
public void setFace(int face) {
this.face = face;
}
//获取字体外观属性值
public int getFace() {
return face;
}
//设置字体样式属性值
public void setStyle(int style) {
this.style = style;
}
//获取字体样式属性值
public int getStyle() {
return style;
}
//设置字体尺寸属性值
public void setSize(int size) {
this.size = size;
}
//获取字体尺寸属性值
public int getSize() {
return size;
}
/*
4.响应条目选择事件
*/
public void itemStateChanged(Item item) {
if (item == faceChoice) {
int f = faceChoice.getSelectedIndex();
switch (f) {
case 0:
face = Font.FACE_SYSTEM;
break;
case 1:
face = Font.FACE_MONOSPACE;
break;
case 2:
face = Font.FACE_PROPORTIONAL;
break;
}
}
else if (item == styleChoice) {
style = 0;
if (styleChoice.isSelected(0)) {
style += Font.STYLE_BOLD;
}
if (styleChoice.isSelected(1)) {
style |= Font.STYLE_ITALIC;
}
if (styleChoice.isSelected(2)) {
style |= Font.STYLE_UNDERLINED;
}
}
else if (item == sizeChoice) {
int s = sizeChoice.getSelectedIndex();
switch (s) {
case 0:
size = Font.SIZE_SMALL;
break;
case 1:
size = Font.SIZE_MEDIUM;
break;
case 2:
size = Font.SIZE_LARGE;
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -