java相关:我制作了一个简易的图像浏览器,只能显示前14张图片,请教大神是怎么回事儿
问题说明:图片一共有33张,名字从1.jpg到33.jpg,只能显示前14张图片,问题截图:具体代码:importjava.applet.*;importjava.awt...
问题说明:图片一共有33张,名字从1.jpg到33.jpg,只能显示前14张图片,问题截图:
具体代码:
import java.applet.*;import java.awt.event.*;import java.awt.*;public class Main extends Applet implements ActionListener{ Image[]m_images; int totallmages=33; int pos=0; Button b1,b2; public void init() { m_images=new Image[totallmages]; for(int i=0;i<totallmages;i++) { m_images[i]=getImage(getDocumentBase(),(i+1)+".jpg"); } b1=new Button("上一张"); b2=new Button("下一张"); setLayout(new BorderLayout()); Panel operate=new Panel(); operate.setLayout(new FlowLayout(FlowLayout.CENTER)); operate.add(b1); operate.add(b2); add("South",operate); b1.addActionListener(this); b2.addActionListener(this); } public void paint(Graphics g) { g.drawImage(m_images[pos],10,10,this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1) { if(pos>0) pos=--pos; else { if(pos==0) pos=32; } } else { pos=++pos%totallmages; } repaint(); }} 展开
具体代码:
import java.applet.*;import java.awt.event.*;import java.awt.*;public class Main extends Applet implements ActionListener{ Image[]m_images; int totallmages=33; int pos=0; Button b1,b2; public void init() { m_images=new Image[totallmages]; for(int i=0;i<totallmages;i++) { m_images[i]=getImage(getDocumentBase(),(i+1)+".jpg"); } b1=new Button("上一张"); b2=new Button("下一张"); setLayout(new BorderLayout()); Panel operate=new Panel(); operate.setLayout(new FlowLayout(FlowLayout.CENTER)); operate.add(b1); operate.add(b2); add("South",operate); b1.addActionListener(this); b2.addActionListener(this); } public void paint(Graphics g) { g.drawImage(m_images[pos],10,10,this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1) { if(pos>0) pos=--pos; else { if(pos==0) pos=32; } } else { pos=++pos%totallmages; } repaint(); }} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询