为什么重绘后没效果?

wenyuanhao 2010-07-08 10:25:46
大家好!
为什么我在数据更新后,repaint(),界面上数据不会更新呢?
...全文
197 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
wenyuanhao 2010-07-16
  • 打赏
  • 举报
回复
这个问题解决了。不是重刷的原因,是因为图片是透明的。很费了番功夫啊!
wenyuanhao 2010-07-12
  • 打赏
  • 举报
回复
我这里不用改变坐标,只是把原来的位置上的文字换掉。测试过了,数据会根据点击按钮来改变。但是界面上的数据就是不会动。很郁闷!
softice_ 2010-07-12
  • 打赏
  • 举报
回复
自己跟踪一下重绘坐标的变化
wenyuanhao 2010-07-12
  • 打赏
  • 举报
回复
有人看出来是什么原因吗?一直没找出来。
haoyizsw 2010-07-09
  • 打赏
  • 举报
回复
贴了一堆的逻辑代码 ,这个打印出来的信息有正确,只能说明的算法执行了没问题
既然逻辑正确了,重要的是要看你绘制函数里是不是绘制当前的信息啊,但是你贴的代码里没看到paint();
找到你的paint()函数 检查一下这个函数是不是写死了,是不是没有根据信息的变化来动态更改显示的内容,要是写死了,你再怎么repaint()它也只能显示第一次绘制的内容
kf156 2010-07-09
  • 打赏
  • 举报
回复
把canvas的paint方法贴出来
prince58 2010-07-09
  • 打赏
  • 举报
回复
WorkSpace 这个类是?? 我没见过,继承canvas的吗?
wenyuanhao 2010-07-09
  • 打赏
  • 举报
回复
源码:
public class ProductListCanvas extends WorkSpace implements IActionListener {
private int index;
private Container conCenter = new Container();
private AppTabedPane apptab = new AppTabedPane();
private int x,x1;
private int position,numTime;
public ProductListCanvas(int index) {
this.super_workSpace();
this.index = index;
setBackgroundImage(Skin.IMG_BG);

this.setOpaque(true);
this.setInsets(Desktop.getCanvasHeight()/24, 0,
Desktop.getCanvasWidth()/32,Desktop.getCanvasWidth()/32);//20
initilize(1,0,0);
}

private void initilize(int index,int position,int numTime ) {

Container conTop = new Container();
conTop.setLayout(new FillLayout(FillLayout.X_AXIS,Desktop.getCanvasWidth()/32));
conTop.setBackgroundImage(Skin.IMG_PRODUCT_MARKED);
conTop.setOpaque(true);

Label labIcon = new Label();
labIcon.setBackgroundImage(Skin.IMG_ELECTRONIC_SMALL);
labIcon.setOpaque(true);


Label labText = new Label();
labText.setText("电子产品"+">>"+"MP4MP43");

conTop.add(labIcon);
conTop.add(labText);

add(conTop, BorderLayout.NORTH);


Label labLeft = new Label();
labLeft.setBackgroundImage(Skin.IMG_MOVELEFT);
labLeft.setOpaque(true);
labLeft.setLink(Constant.BUTTON_LEFT, this, null);
labLeft.setActionListener(this);

Label labRight = new Label();
labRight.setBackgroundImage(Skin.IMG_MOVERIGHT);
labRight.setOpaque(true);
labRight.setLink(Constant.BUTTON_RIGHT, this, null);
labRight.setActionListener(this);

conCenter.setLayout(new BorderLayout());
conCenter.setInsets(Desktop.getCanvasHeight()/48,
Desktop.getCanvasHeight()/48, 0, 0);
conCenter.add(labLeft,BorderLayout.WEST);
conCenter.add(createApptab(index,position,numTime),BorderLayout.CENTER);
conCenter.add(labRight,BorderLayout.EAST);

add(conCenter, BorderLayout.CENTER);
add(MenuHandler.getInstance().getUserMenu(), BorderLayout.SOUTH);
}
private AppTabedPane createApptab(int index,int direction,int numTime){
SelectedTabCon tabMp4,tabPhone,tabComputer,tabTV,tabMoveL,
tabMoveR,tabU_Disk;
String productStr[] = {"MP4MP3","手机","电脑","小家电","U盘"};
int strLength = productStr.length;

//direction=1为向左移动,direction=2向右移动
if(index==1 && (direction==0 || direction==1 || direction==2) && numTime==0){//首次加载
Logger.log("首次加载numTime",numTime);
tabMp4 = new SelectedTabCon(1);
apptab.addTab("MP4MP3",tabMp4);
tabPhone = new SelectedTabCon(2);
apptab.addTab("手机",tabPhone);
tabComputer = new SelectedTabCon(3);
apptab.addTab("电脑",tabComputer);
}else if((numTime==strLength )||(numTime>strLength)){//循环5次,第5次,numTime=6
Logger.log("回到最初的状态",numTime);
tabMp4 = new SelectedTabCon(1);
apptab.addTab("MP4MP3",tabMp4);
tabPhone = new SelectedTabCon(2);
apptab.addTab("手机", tabPhone);
tabComputer = new SelectedTabCon(3);
apptab.addTab("电脑",tabComputer);
}else if(numTime==strLength-1 && direction==1){//左移时,如果是第4次循环时
Logger.log("左移时第4次循环时numTime",numTime);
tabMp4 = new SelectedTabCon(1);
apptab.addTab(productStr[numTime-1],tabMp4);
tabPhone = new SelectedTabCon(2);
apptab.addTab(productStr[0],tabPhone);
tabComputer = new SelectedTabCon(3);
apptab.addTab(productStr[1],tabComputer);
}else if(numTime==strLength-2 && direction==1){//左移时
Logger.log("左移3次numTime",numTime);
tabMp4 = new SelectedTabCon(1);
apptab.addTab(productStr[strLength-2],tabMp4);
tabPhone = new SelectedTabCon(2);
apptab.addTab(productStr[strLength-1],tabPhone);
tabComputer = new SelectedTabCon(3);
apptab.addTab(productStr[0],tabComputer);
}else if(direction==1&& (numTime>0 && numTime<3)){//左移时
Logger.log("左移时12次numTime",numTime);
tabMp4 = new SelectedTabCon(1);
apptab.addTab(productStr[numTime],tabMp4);
Logger.log("左移12次时",productStr[numTime]);
tabPhone = new SelectedTabCon(2);
apptab.addTab(productStr[numTime+1],tabPhone);
Logger.log("左移时12",productStr[numTime+1]);
tabComputer = new SelectedTabCon(3);
apptab.addTab(productStr[numTime+2],tabComputer);
Logger.log("左移时12",productStr[numTime+2]);
}else if(numTime==strLength-1 && direction==2){//右移4次
Logger.log("右移4次",numTime);
tabMp4 = new SelectedTabCon(1);
apptab.addTab(productStr[1],tabMp4);
tabPhone = new SelectedTabCon(2);
apptab.addTab(productStr[2],tabPhone);
tabComputer = new SelectedTabCon(3);
apptab.addTab(productStr[3],tabComputer);
}else if(numTime==1&&direction==2){//右移时1次
Logger.log("右移1次时",numTime);
tabMp4 = new SelectedTabCon(1);
apptab.addTab(productStr[strLength-1],tabMp4);
tabPhone = new SelectedTabCon(2);
apptab.addTab(productStr[0],tabPhone);
tabComputer = new SelectedTabCon(3);
apptab.addTab(productStr[1],tabComputer);
}else if(numTime==2&&direction==2){//右移2次时
Logger.log("右移2次时",numTime);
tabMp4 = new SelectedTabCon(1);
apptab.addTab(productStr[strLength-2],tabMp4);
tabPhone = new SelectedTabCon(2);
apptab.addTab(productStr[strLength-1],tabPhone);
tabComputer = new SelectedTabCon(3);
apptab.addTab(productStr[0],tabComputer);
}else if(numTime==3 && direction==2){//右移时
Logger.log("右移3次时",numTime);
tabMp4 = new SelectedTabCon(1);
apptab.addTab(productStr[numTime-1],tabMp4);
tabPhone = new SelectedTabCon(2);
apptab.addTab(productStr[numTime],tabPhone);
tabComputer = new SelectedTabCon(3);
apptab.addTab(productStr[numTime+1],tabComputer);
}
return apptab;
}


public void actionPerformed(int cmd, Object obj) {
switch (cmd) {
case Constant.BUTTON_LEFT:
if(x>4){
x=1;
removeAll();
initilize(1,1,0);
repaint();
Logger.log("x的值",x);
}else{
x++;
removeAll();
initilize(1,1,x);
repaint();
Logger.log("x++的值",x);
}



break;
case Constant.BUTTON_RIGHT:
if(x1>4){
x1=1;
initilize(1,2,0);
repaint();
Logger.log("x1的值",x1);
}else{
x1++;
initilize(1,2,x1);
repaint();
Logger.log("x1==的值",x1);
}

break;

}

}
wenyuanhao 2010-07-09
  • 打赏
  • 举报
回复
我这个是在每次点击按钮,都会重新加载组件,将组件上的文字替换掉。在重新加载后,通过打印测试语句,数据会变化,但是就是不能显示变化后的数据。我在重新加载组件后,都调用了repaint方法。
haoyizsw 2010-07-09
  • 打赏
  • 举报
回复
肯定是绘制函数有问题呗,贴代码啊 ,要不谁知道你具体哪错了?
mochhk 2010-07-09
  • 打赏
  • 举报
回复
看看你的paint方法内的数据有没有跟着变化。如果变化了可以试试用serviceRepaints()方法强制重绘一下。
凡员外 2010-07-09
  • 打赏
  • 举报
回复
没有影响到
wenyuanhao 2010-07-09
  • 打赏
  • 举报
回复
这个遵循另外的sdk中的语法,和java不完全相同的。我这里只是更新图片是上的文字,这个它是通过调用其中的组件里面的paint方法。有些复杂,我先贴出来你们帮看看。
protected void paintComponent(Base g) {

Picture m_tabSBg = Skin.getPicture(tabSBg);
Picture m_tabBg = Skin.getPicture(tabBg);
Picture m_tabSBg2 = Skin.getPicture(tabSBg2);
Picture m_tabBg2 = Skin.getPicture(tabBg2);


Rect tabArea = calculateTabArea();
int w = m_tabSBg.getWidth();
int w2 = m_tabSBg2.getWidth();
Vector titles = m_tabed.m_titles;
g.setFont(getWidgetFont());
int x = tabArea.x+4;
//for循环和下面的paintTab()方法注释后,好像不影响7.6
for (int i = 0; i < titles.size(); i++) {
boolean isSelected = (i == m_tabed.getSelectedIndex());
if(titles.size() == 4){
paintTab(g, isSelected, (String) titles.elementAt(i), x, tabArea.y,
w2, tabArea.height,true);
x += w2+4;

}else if(titles.size()== 5) {
paintTab(g, isSelected, (String) titles.elementAt(i), x, tabArea.y,
w, tabArea.height,false);
x += w+3;
}else {
// Logger.log("w22",w2);
paintTab(g, isSelected, (String) titles.elementAt(i), x, tabArea.y,
w2, tabArea.height,true);
// x += w2+4;//这里是该图片的间隔的
x += w2;
}

}


if (m_tabed.m_title != null) {
g.setFont(BaseSkin.FONT_DEFAULT);
g.drawString(m_tabed.m_title, getX() + 5, getY()
+ (getHeight() >> 1), Base.LEFT | Base.BOTTOM);
}
if (m_tabed.m_icon != null) {
g.drawPicture(m_tabed.m_icon, getX() + 5, getY()
+ (getHeight() >> 1), Base.LEFT | Base.TOP);
}
//
if (m_tabed.m_title != null) {
g.setFont(BaseSkin.FONT_DEFAULT);
g.drawString(m_tabed.m_title, getX(), getY()
+ (getHeight() >> 1), Base.LEFT | Base.BOTTOM);
}
if (m_tabed.m_icon != null) {
g.drawPicture(m_tabed.m_icon, getX(), getY()
+ (getHeight() >> 1), Base.LEFT | Base.TOP);
}

}

protected void paintTab(Base g, boolean isSelected, String title, int x,
int y, int w, int h,boolean isBig) {
Picture tabBgs = null;


g.setFont(BaseSkin.FONT_DEFAULT);
if(isBig == true){
Picture m_tabBg2 = Skin.getPicture(tabBg2);
tabBgs = m_tabBg2;
if (isSelected) {
Picture m_tabSBg2 = Skin.getPicture(tabSBg2);
tabBgs = m_tabSBg2;
g.setColor(getForeground());
if (isFocused()) {
g.setColor(0xffffff);
}
} else {
g.setColor(getForeground());
}
}else{
Picture m_tabBg = Skin.getPicture(tabBg);
tabBgs = m_tabBg;
if (isSelected) {
Picture m_tabSBg = Skin.getPicture(tabSBg);
tabBgs = m_tabSBg;
g.setColor(getForeground());
if (isFocused()) {
g.setColor(0xffffff);
}
} else {
g.setColor(getForeground());
}

}
g.drawPicture(tabBgs, x + (w >> 1), y + (h >> 1), Base.HCENTER
| Base.VCENTER);
g.drawString(title, x + (w >> 1), y + (h >> 1), Base.HCENTER
| Base.VCENTER);

// if(isFocuesd() && isSelected){
// g.setStrokeStyle(Base.SOLID);
// g.setColor(getBorderColor());
// g.drawRect(x + 2, y + 5, w - 5, h - 7);
// }
}

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧