public class RateScreen extends MainScreen {
int mScrWidth = Display.getWidth();
int mScrHeight = Display.getHeight();
int mImgWidth = 40;
int mImgHeight = 40;
final BitmapField,bitmapField1,bitmapField2,bitmapField3,
bitmapField4,bitmapField5,bitmapField6;
final HorizontalFieldManager hfm ;
FontFamily ff;{
try{
ff = FontFamily.forName("Times New Roman");}catch(Exception e){}}
// Use style bits from Font class, e.g. Font.BOLD
Font f = ff.getFont(Font.BOLD, 36);
EncodedImage mImages[];
Bitmap mImgTable,mImgTable1,mImgTable2,mImgTable3,
mImgTable4,mImgTable5,mImgTable6;
LabelField labelfield1,labelfield2,labelfield3,labelfield4,l1,l2,l3;
public RateScreen() {
super();
labelfield1 = new LabelField("",Field.FIELD_HCENTER);
add(labelfield1);
labelfield2 = new LabelField("Rate This App",Field.FIELD_HCENTER);
labelfield2.setFont(f);
add(labelfield2);
labelfield3 = new LabelField("",Field.FIELD_HCENTER);
add(labelfield3);
labelfield4 = new LabelField("Please choose one
of the options below",Field.FIELD_HCENTER);
add(labelfield4);
l1 = new LabelField("",Field.FIELD_HCENTER);
add(l1);
prepareImages();
mImgTable=paintImages();
mImgTable1=paintImages1();
mImgTable2=paintChar1();
mImgTable3=paintChar2();
mImgTable4=paintChar3();
mImgTable5=paintChar4();
mImgTable6=paintChar5();
hfm = new HorizontalFieldManager(Field.FIELD_HCENTER|Field.FIELD_VCENTER);
final BitmapField bitmapField = new BitmapField
(mImgTable , BitmapField.FOCUSABLE);
bitmapField6 = new BitmapField(mImgTable1 , BitmapField.FOCUSABLE);
bitmapField1 = new BitmapField(mImgTable , BitmapField.FOCUSABLE)
{
protected boolean navigationClick(int status, int time )
{ try{
Dialog.alert("image changed");
hfm.replace(bitmapField1, bitmapField6);
hfm.replace(bitmapField2, bitmapField);
hfm.replace(bitmapField3, bitmapField);
hfm.replace(bitmapField4, bitmapField);
hfm.replace(bitmapField5, bitmapField);
}catch(Exception e){
Dialog.alert("choose only one"+e);
}
return true;}};
hfm.add(bitmapField1);
bitmapField2 = new BitmapField(mImgTable , BitmapField.FOCUSABLE)
{
protected boolean navigationClick(int status, int time )
{ try{
//Dialog.alert("image changed");
hfm.replace(bitmapField1, bitmapField);
hfm.replace(bitmapField2, bitmapField6);
hfm.replace(bitmapField3, bitmapField);
hfm.replace(bitmapField4, bitmapField);
hfm.replace(bitmapField5, bitmapField);
}catch(Exception e){
Dialog.alert("choose only one"+e);
}
return true;
}
};
hfm.add(bitmapField2);
bitmapField3 = new BitmapField(mImgTable , BitmapField.FOCUSABLE){
protected boolean navigationClick(int status, int time )
{ try{
//Dialog.alert("image changed");
hfm.replace(bitmapField1, bitmapField);
hfm.replace(bitmapField2, bitmapField);
hfm.replace(bitmapField3, bitmapField6);
hfm.replace(bitmapField4, bitmapField);
hfm.replace(bitmapField5, bitmapField);
}catch(Exception e){
Dialog.alert("choose only one"+e);
}
return true;
}};
bitmapField4 = new BitmapField(mImgTable , BitmapField.FOCUSABLE)
{
protected boolean navigationClick(int status, int time )
{ try{
// Dialog.alert("image changed");
hfm.replace(bitmapField1, bitmapField);
hfm.replace(bitmapField2, bitmapField);
hfm.replace(bitmapField3, bitmapField);
hfm.replace(bitmapField4, bitmapField6);
hfm.replace(bitmapField5, bitmapField);
}catch(Exception e){
Dialog.alert("choose only one"+e);
}
return true;
}
};
bitmapField5 = new BitmapField(mImgTable , BitmapField.FOCUSABLE)
{
protected boolean navigationClick(int status, int time )
{ try{
// Dialog.alert("image changed")
hfm.replace(bitmapField1, bitmapField1);
hfm.replace(bitmapField2, bitmapField1);
hfm.replace(bitmapField3, bitmapField1);
hfm.replace(bitmapField4, bitmapField1);
hfm.replace(bitmapField5, bitmapField6);
}catch(Exception e){
Dialog.alert("choose only one"+e);
}
return true;
}
};
hfm.add(bitmapField3);hfm.add(bitmapField4);hfm.add(bitmapField5);
add(hfm);
l2 = new LabelField("",Field.FIELD_HCENTER);
add(l2);
final HorizontalFieldManager hfm1 = new HorizontalFieldManager
(Field.FIELD_HCENTER|Field.FIELD_VCENTER);
BitmapField bitmapField7 = new BitmapField
(mImgTable2 , BitmapField.FOCUSABLE);
hfm1.add(bitmapField7);
BitmapField bitmapField8 = new BitmapField
(mImgTable3 , BitmapField.FOCUSABLE);
hfm1.add(bitmapField8);
BitmapField bitmapField9 = new BitmapField
(mImgTable4 , BitmapField.FOCUSABLE);
hfm1.add(bitmapField9);
BitmapField bitmapField10 = new BitmapField
(mImgTable5 , BitmapField.FOCUSABLE);
hfm1.add(bitmapField10);
BitmapField bitmapField11 = new BitmapField
(mImgTable6 , BitmapField.FOCUSABLE);
hfm1.add(bitmapField11);
add(hfm1);
l3 = new LabelField("",Field.FIELD_HCENTER);
add(l3);
ButtonField btn=new ButtonField("Rate",Field.FIELD_HCENTER){
protected boolean navigationClick(int status, int time)
{
UiApplication.getUiApplication().pushScreen(new MyScreen());
return true;
}
};
add(btn);
}
private void prepareImages() {
mImages=new EncodedImage[3];
EncodedImage image = EncodedImage
.getEncodedImageResource("star.png");
mImages[0] = sizeImage(image, mImgWidth, mImgHeight);
EncodedImage image1 = EncodedImage
.getEncodedImageResource("star_blue.png");
mImages[1] = sizeImage(image1, mImgWidth, mImgHeight);
}
private Bitmap paintImages() {
Bitmap result = new Bitmap(70, 50);
Graphics graphics = new Graphics(result);
EncodedImage image = mImages[0];
graphics.drawImage(15,5, mImgWidth, mImgHeight, image, 0,
0, 0);
return result;
}
private Bitmap paintImages1() {
Bitmap result = new Bitmap(70, 50);
Graphics graphics = new Graphics(result);
EncodedImage image = mImages[1];
graphics.drawImage(15,5, mImgWidth, mImgHeight, image, 0,
0, 0);
return result;
}
private Bitmap paintChar1() {
Bitmap result = new Bitmap(70, 60);
Graphics graphics = new Graphics(result);
graphics.drawText("Very", 15, 0);
graphics.drawText("bad", 18, 30);
return result;
}
private Bitmap paintChar2() {
Bitmap result = new Bitmap(70, 60);
Graphics graphics = new Graphics(result);
graphics.drawText("Bad", 15, 0);
return result;
}
private Bitmap paintChar3() {
Bitmap result = new Bitmap(80, 60);
Graphics graphics = new Graphics(result);
graphics.drawText("Average", 0, 0);
return result;
}
private Bitmap paintChar4() {
Bitmap result = new Bitmap(70, 60);
Graphics graphics = new Graphics(result);
graphics.drawText("Good", 15, 0);
return result;
}
private Bitmap paintChar5() {
Bitmap result = new Bitmap(70, 60);
Graphics graphics = new Graphics(result);
graphics.drawText("Very", 15, 0);
graphics.drawText("good", 15, 30);
return result;
}
public EncodedImage sizeImage(EncodedImage image, int width,
int height) {
EncodedImage result = null;
int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
int requiredWidthFixed32 = Fixed32.toFP(width);
int requiredHeightFixed32 = Fixed32.toFP(height);
int scaleXFixed32 = Fixed32.div(currentWidthFixed32,
requiredWidthFixed32);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32,
requiredHeightFixed32);
result = image.scaleImage32(scaleXFixed32, scaleYFixed32);
return result;
}}
当我第一次点击位图时,位图会发生变化,但如果我点击其他,那么它会显示异常并且位图不会被更改。 我想点击任何位图然后它被其他位图改变。 如果有人不帮助我,我怎么能这样做呢。
答案 0 :(得分:2)
请勿将HorizontalFieldmanager
替换为hfm.replace(bitmapField1, bitmapField6);
。只需为您的所有图片替换bitmapField1.setBitmap(bitmapField6);
图像。
它在我的案子里工作..