当前位置:编程学习 > JAVA >>

CardLayout扑克牌轮换程序

我加了图片,可运行时不显示图片,这是怎么回事???

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.Timer;

public class Chick extends Frame {
public Chick() {
initComponent();
}

private void initComponent() {
setTitle("技能演示");
setSize(800, 550);

final CardLayout cl = new CardLayout();
setLayout(cl);
final String[] img = { "bs1", "bs2", "bs3" };
for (String e : img) {
add(new DrawCard("image" + e + ".png"), e);
}
showCard(cl, this, img);
addWindowListener(new WindowAdapter() {
public void windowClosing(final WindowEvent evt) {
System.exit(0);
}
});
}

private void showCard(final CardLayout cl, final Frame frame,
final String[] img) {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
int i = 0;

public void run() {
cl.show(frame, img[i]);
i = i == 3 ? 0 : ++i;

}

}, 0, 1000);
}

public static void main(String[] args) {
new Chick().setVisible(true);

}

}

class DrawCard extends Canvas {
private String imageName;

public DrawCard(String imageName) {
this.imageName = imageName;

}

public void paint(Graphics g) {
g.drawImage(Toolkit.getDefaultToolkit().getImage(imageName), 60, 10,
this);

}

} CardLayout
补充:Java ,  Java相关
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,