那个action搞成静态方法也没必要吧
搞成静态的话你只能实例化调用方法了
加了这些代码private static final long serialVersionUID = 1L
Image imgs[]=new Image[5]
repaint()
改后昌敏轿代码如下:
import java.awt.*
import java.awt.event.*
import java.applet.Applet
public class PlayAudio extends Applet implements ActionListener {
private static final long serialVersionUID = 1L
Image imgs[]=new Image[5]
Button b2
public void init() {
setLayout(new FlowLayout())// 使用布局管理器
imgs[0]=getImage(getCodeBase(),"1.jpg")
imgs[1]=getImage(getCodeBase(),"2.jpg")
imgs[2]=getImage(getCodeBase(),"3.jpg")
imgs[3]=getImage(getCodeBase(),"4.jpg")
imgs[4]=getImage(getCodeBase(),"5.jpg")
b2=new Button("下一张")// 定义Play按钮
b2.addActionListener(this)// 给Play按钮添加一个监听事件
add(b2)
}
private static int count = 0
public void actionPerformed(ActionEvent e)
{
//if(e.getSource() == b2)
//{
count=++count%5
repaint()
//}
}
public void paint(Graphics g)
{
g.drawImage(imgs[count],0,40,this)
}
}
==============================
g.drawImage("m"+count,0,40,this)
这拿拿个地方需要传进耐肆image类型的对象:m"+count是字符串类型
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)