gpt4 book ai didi

java-me - J2ME 图像项目幻灯片

转载 作者:行者123 更新时间:2023-12-02 18:10:01 27 4
gpt4 key购买 nike

我尝试过在 j2me 中使用图像幻灯片。下面是我的图像幻灯片代码。但它会执行图像不幻灯片并且不显示吗。

如果我单击播放按钮,图像将自动从图像 0.jpg 幻灯片放映到图像 7.jpg。

幻灯片的这个变量

 String[] Foto={"/0.jpg", "/1.jpg","/2.jpg", "/3.jpg","/4.jpg", "/5.jpg","/6.jpg", "/7.jpg"};
Image[] img = new Image[8];

这个循环用于显示图像..

protected void paint(Graphics g) {
try {

g.setColor(255, 0, 0 );
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(255,0, 0);
g.drawString(text,getWidth()/2, getHeight()/2,
Graphics.TOP | Graphics.HCENTER);
g.setColor(0, 255, 0);
g.setColor(123,0,255);
g.drawRect(74,74, 100,100 );
g.drawRect(72,72, 104,104 );

for ( int i=0;i<8;i++)
if (i==1)
if (i==2)
img[i]=Image.createImage(Foto[i]);
g.drawImage(img [1],124,124, Graphics.VCENTER | Graphics.HCENTER );
g.drawImage(img [2],124,124, Graphics.VCENTER | Graphics.HCENTER );
g.drawImage(img [1],124,124, Graphics.VCENTER | Graphics.HCENTER );

} catch (IOException ex) {
ex.printStackTrace();
}}

最佳答案

Paint() 中有一个循环,它将在 Canvas 上一张一张地绘制图像。尝试使用全局变量 currentIndex = 0

protected void paint(Graphics g) {
try {

g.setColor(255, 0, 0 );
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(255,0, 0);
g.drawString(text,getWidth()/2, getHeight()/2,
Graphics.TOP | Graphics.HCENTER);
g.setColor(0, 255, 0);
g.setColor(123,0,255);
g.drawRect(74,74, 100,100 );
g.drawRect(72,72, 104,104 );


img = Image.createImage(Foto[currentIndex]);
g.drawImage(img,124,124, Graphics.VCENTER | Graphics.HCENTER );

} catch (IOException ex) {
ex.printStackTrace();
}}

onClick你的按钮,你可以尝试

currentIndex++;
repaint();

如果您想要动画,您可以在重绘图像时更改 x 或 y

关于java-me - J2ME 图像项目幻灯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13549127/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com