java 编一个程序按下按钮(button)实现换下一张照片 我写的 帮改一下

来源:百度知道 编辑:UC知道 时间:2024/06/18 04:04:10
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() ==