我用纯servlets写了一下,你可以看看:
第一个servlet,Index.java:
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Index extends HttpServlet {
public Index() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gbk");
PrintWriter pw = response.getWriter();
pw.println("");
pw.println("
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是字符串类型