import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class PlayAudio extends Applet implements ActionListener {
Image m1,m2,m3,m4,m5;
Button b2;
public void init() {
setLayout(new FlowLayout()); // 使用布局管理器
m1=getImage(getCodeBase(),"1.jpg");
m2=getImage(getCodeBase(),"2.jpg");
m3=getImage(getCodeBase(),"3.jpg");
m4=getImage(getCodeBase(),"4.jpg");
m5=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++;
}
}
public void paint(Graphics g)
{
g.drawImage("m"+count,0,40,this);
}
}
("m"+count,0,40,this); 这是语法错误吗?
怎么不对呢?能说一下原因吗?
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是字符串类型