我用NetBeans的图形界面来实现图片的显示。但由于我的图片实在太多了,有100多张,然后一个页面(interface)就显示20张,然后我想用bouton:(上一页,下一页)来显示我的图片,点击(下一页),就会换新的20页图片,点击(上一页)就会显示之前的图片。不知道大家有没有好的建议
我的图片路径:D:\image下。每张图片的像素都是固定,一样的我现在做成的界面大致是这样的:
我想在:下面加两个Bouton(上一页,下一页),好让他能更换图片
希望大家能给点意见。100分奖赏

解决方案 »

  1.   

    这个分页的思想跟Web分页的思想是一样的;
    首先设置要查询的页数,每页查询的条数,然后每次分页的时候都去请求一次服务;
      

  2.   

    楼主可以用些JS组件~推荐个tiltviewer,以前用过一个,感觉不错~可惜不能传~
      

  3.   

    我不知道怎么让他一页同时换掉多张,我现在弄了一下,如果一页只让他显示一张来,然后点下一页,这样倒没啥大问题
    而且我用的很笨的方法,
     public static final String[] IMAGE_NAMES  = { "D:/学习/I_r/pic_film/1Gars1Fille.jpg", "D:/学习/I_r/pic_film/3HommesCouffin.jpg",
            "D:/学习/I_r/pic_film/4 mariages 1 enterrement.jpg", 
            "D:/学习/I_r/pic_film/5èmeElément.jpg","D:/学习/I_r/pic_film/Avatar.jpg"  
            ,"D:/学习/I_r/pic_film/Taxi.jpg"};都是静态引用所有的图片,大家有没有好点的方法,动态引用。就不用一张张的放进去了然后我用这个方法:
     public void actionPerformed(ActionEvent e) {
            Object src = e.getSource();
            if (src == btnFirst) {
                currentIndex = 0;
            } else if (src == btnPre) {
                currentIndex = currentIndex == 0 ? 0 : currentIndex - 1;
            } else if (src == btnNext) {
                currentIndex = currentIndex == IMAGE_NAMES.length - 1 ? currentIndex
                        : currentIndex + 1;
            } else if (src == btnLast) {
                currentIndex = IMAGE_NAMES.length - 1;
            }        imageLabel.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex]));
        }然后倒是能实现一张一张图片的变换
    大家能不能再给点建议?
      

  4.   

    用grid布局吧,结合上边的说的分页查询,一次加载一页的图片到网格中
      

  5.   

    恩这些我都实现了,没什么问题了
    只是我想知道大家有没有办法,不要静态引用
    public static final String[] IMAGE_NAMES = { "D:/学习/I_r/pic_film/1Gars1Fille.jpg", "D:/学习/I_r/pic_film/3HommesCouffin.jpg",
      "D:/学习/I_r/pic_film/4 mariages 1 enterrement.jpg",  
      "D:/学习/I_r/pic_film/5èmeElément.jpg","D:/学习/I_r/pic_film/Avatar.jpg"   
      ,"D:/学习/I_r/pic_film/Taxi.jpg"};
    图片的方法,毕竟有100多张,这样真的很累啊
    谢谢大家了
    我想直接从
    "D:/学习/I_r/pic_film/  这个路径下读取图片。然后包装在数组IMAGE_NAMES下
      

  6.   


    File imageFile = new File("D:/学习/I_r/pic_film");
    String[] imageName = imageFile.list(new FilenameFilter(){
        public boolean accept(File dir, String name) {
             return name.trim().split("\\.")[1].equals("jpg")? true : false;
        }
    });
    如果数据量大 可以用线程 等待激活方式 在accept中进行处理
      

  7.   


       return name.trim().split("\\.")[1].equals("jpg");
      

  8.   


       String[] imageFilePath = new String[imageName.length];
       for(int i=0;i<imageName.length;i++) {
          imageFilePath[i] = imageFile.getAbsolutePath() + "\\" + imageName[i];
       }
        
      

  9.   

    这是我写的分页代码,如果用静态的方法就没啥问题,但是用动态的话还是有问题
    请大家帮下忙
    谢谢啦package 图片分页显示;import java.awt.BorderLayout;
    import java.awt.CardLayout;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.FilenameFilter;import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;public class Copy_2_of_ImageFrame extends JFrame implements ActionListener {
        // le nom d'image
       /* public static final String[] IMAGE_NAMES  = { "D:/学习/I_r/pic_film/1Gars1Fille.jpg",
         "D:/学习/I_r/pic_film/3HommesCouffin.jpg", "D:/学习/I_r/pic_film/4 mariages 1 enterrement.jpg", 
            "D:/学习/I_r/pic_film/5èmeElément.jpg","D:/学习/I_r/pic_film/Avatar.jpg"  
            ,"D:/学习/I_r/pic_film/Taxi.jpg","D:/学习/I_r/pic_film/Camelot.jpg","D:/学习/I_r/pic_film/Mulan.jpg",
            "D:/学习/I_r/pic_film/BossuNotreDame.jpg","D:/学习/I_r/pic_film/Cendrillon.jpg",
            "D:/学习/I_r/pic_film/Amour Gloire Beauté.jpg","D:/学习/I_r/pic_film/AmélieP.jpg",
            "D:/学习/I_r/pic_film/ArthurMinimoys.jpg","D:/学习/I_r/pic_film/AristoChats.jpg",
            "D:/学习/I_r/pic_film/Taxi3.jpg","D:/学习/I_r/pic_film/Taxi2.jpg"};*/
      private JButton              btnFirst, btnNext, btnPre, btnLast;
        private int                  currentIndex = 0;
        private JLabel               imageLabel,imageLabel2,imageLabel3;  File imageFile = new File("D:/学习/I_r/pic_film");
     
       public  String[] imageName = imageFile.list(new FilenameFilter(){
            public boolean accept(File dir, String name) {
                 return name.trim().split("\\.")[1].equals("jpg");
            }
        }   );    public String[] IMAGE_NAMES = new String [imageName.length];
       for(int i=0;i<imageName.length;i++) {
       IMAGE_NAMES[i] = imageFile.getAbsolutePath() + "\\" + imageName[i];
       }
      
          
        public Copy_2_of_ImageFrame() {
            super("Image");
            setSize(600, 400);
            setLayout(new  FlowLayout());        init();        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setResizable(false);
            setVisible(true);
        }    private void init() {
            // Quatre bouton
            JPanel buttonsPanel = new JPanel();
            add(buttonsPanel, BorderLayout.CENTER);        btnFirst = new JButton("Primier");
            btnPre = new JButton("Précédent");
            btnNext = new JButton("Suivant");
            btnLast = new JButton("Dernier");
            buttonsPanel.add(btnFirst);
            buttonsPanel.add(btnPre);
            buttonsPanel.add(btnNext);
            buttonsPanel.add(btnLast);
            
            btnFirst.addActionListener(this);
            btnPre.addActionListener(this);
            btnNext.addActionListener(this);
            btnLast.addActionListener(this);        // Image
            imageLabel = new JLabel();
            imageLabel.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex]));
            add(imageLabel, FlowLayout.LEFT);
            imageLabel2 = new JLabel();
            imageLabel2.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex+1]));
            add(imageLabel2, FlowLayout.CENTER);
            imageLabel3 = new JLabel();
            imageLabel3.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex+2]));
            add(imageLabel3, FlowLayout.RIGHT);
           
        }    public void actionPerformed(ActionEvent e) {
            Object src = e.getSource();
            if (src == btnFirst) {
             currentIndex = 0;
            } else if (src == btnPre) {
            
                currentIndex = currentIndex == 0 ? 0 : currentIndex - 3;
              
            
            } else if (src == btnNext) {
            
                currentIndex = currentIndex == IMAGE_NAMES.length - 1 ? currentIndex
                        : currentIndex + 3;
               
            
            } else if (src == btnLast) {
                currentIndex = IMAGE_NAMES.length - 1;
            }
            
            
            if(currentIndex<IMAGE_NAMES.length - 2){
             imageLabel.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex]));
            imageLabel2.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex+1]));
            imageLabel3.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex+2]));
            
            }
            else{
             imageLabel.setIcon(new ImageIcon(IMAGE_NAMES[IMAGE_NAMES.length - 1]));
             imageLabel2.setIcon(new ImageIcon(IMAGE_NAMES[0]));
                imageLabel3.setIcon(new ImageIcon(IMAGE_NAMES[1]));
                
            }
            
        }    public static void main(String[] args) {
            new Copy_2_of_ImageFrame();
        }
    }
      

  10.   

    错误是因为 for循环要放到方法体中才能执行 import java.awt.BorderLayout;
    import java.awt.CardLayout;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.FilenameFilter;import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;public class Copy_2_of_ImageFrame extends JFrame implements ActionListener {
      // le nom d'image
      /* public static final String[] IMAGE_NAMES = { "D:/学习/I_r/pic_film/1Gars1Fille.jpg",
      "D:/学习/I_r/pic_film/3HommesCouffin.jpg", "D:/学习/I_r/pic_film/4 mariages 1 enterrement.jpg",  
      "D:/学习/I_r/pic_film/5èmeElément.jpg","D:/学习/I_r/pic_film/Avatar.jpg"   
      ,"D:/学习/I_r/pic_film/Taxi.jpg","D:/学习/I_r/pic_film/Camelot.jpg","D:/学习/I_r/pic_film/Mulan.jpg",
      "D:/学习/I_r/pic_film/BossuNotreDame.jpg","D:/学习/I_r/pic_film/Cendrillon.jpg",
      "D:/学习/I_r/pic_film/Amour Gloire Beauté.jpg","D:/学习/I_r/pic_film/AmélieP.jpg",
      "D:/学习/I_r/pic_film/ArthurMinimoys.jpg","D:/学习/I_r/pic_film/AristoChats.jpg",
      "D:/学习/I_r/pic_film/Taxi3.jpg","D:/学习/I_r/pic_film/Taxi2.jpg"};*/
      public String[] IMAGE_NAMES = getImageName();
      private JButton btnFirst, btnNext, btnPre, btnLast;
      private int currentIndex = 0;
      private JLabel imageLabel,imageLabel2,imageLabel3;  public Copy_2_of_ImageFrame() {
      super("Image");
      setSize(600, 400);
      setLayout(new FlowLayout());  init();  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setResizable(false);
      setVisible(true);
      }
     /**
      * @author Administrator
      * @return 图片绝对路径的数组集合
      */
      private String[] getImageName() {
      File imageFile = new File("D:/学习/I_r/pic_film");
      
      String[] imageName = imageFile.list(new FilenameFilter(){
      public boolean accept(File dir, String name) {
      return name.trim().split("\\.")[1].equals("jpg");
      }
      });   String[] IMAGE_NAMES = new String [imageName.length];
      for(int i=0;i<imageName.length;i++) {
      IMAGE_NAMES[i] = imageFile.getAbsolutePath() + "\\" + imageName[i];
      }
      return IMAGE_NAMES;
    }private void init() {
      // Quatre bouton
      JPanel buttonsPanel = new JPanel();
      add(buttonsPanel, BorderLayout.CENTER);  btnFirst = new JButton("Primier");
      btnPre = new JButton("Précédent");
      btnNext = new JButton("Suivant");
      btnLast = new JButton("Dernier");
      buttonsPanel.add(btnFirst);
      buttonsPanel.add(btnPre);
      buttonsPanel.add(btnNext);
      buttonsPanel.add(btnLast);
        
      btnFirst.addActionListener(this);
      btnPre.addActionListener(this);
      btnNext.addActionListener(this);
      btnLast.addActionListener(this);  // Image
      imageLabel = new JLabel();
      imageLabel.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex]));
      add(imageLabel, FlowLayout.LEFT);
      imageLabel2 = new JLabel();
      imageLabel2.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex+1]));
      add(imageLabel2, FlowLayout.CENTER);
      imageLabel3 = new JLabel();
      imageLabel3.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex+2]));
      add(imageLabel3, FlowLayout.RIGHT);
        
      }  public void actionPerformed(ActionEvent e) {
      Object src = e.getSource();
      if (src == btnFirst) {
      currentIndex = 0;
      } else if (src == btnPre) {
      
      currentIndex = currentIndex == 0 ? 0 : currentIndex - 3;
        
      
      } else if (src == btnNext) {
      
      currentIndex = currentIndex == IMAGE_NAMES.length - 1 ? currentIndex
      : currentIndex + 3;
        
      
      } else if (src == btnLast) {
      currentIndex = IMAGE_NAMES.length - 1;
      }
        
        
      if(currentIndex<IMAGE_NAMES.length - 2){
      imageLabel.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex]));
    imageLabel2.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex+1]));
    imageLabel3.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex+2]));
      
      }
      else{
      imageLabel.setIcon(new ImageIcon(IMAGE_NAMES[IMAGE_NAMES.length - 1]));
      imageLabel2.setIcon(new ImageIcon(IMAGE_NAMES[0]));
      imageLabel3.setIcon(new ImageIcon(IMAGE_NAMES[1]));
        
      }
        
      }  public static void main(String[] args) {
      new Copy_2_of_ImageFrame();
      }
    }
      

  11.   

    老大,这个会出错啊, IMAGE_NAMES这个数组我是必须得申明的imageLabel = new JLabel();
      imageLabel.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex]));
      add(imageLabel, FlowLayout.LEFT);
      imageLabel2 = new JLabel();
      imageLabel2.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex+1]));
      add(imageLabel2, FlowLayout.CENTER);
      imageLabel3 = new JLabel();
      imageLabel3.setIcon(new ImageIcon(IMAGE_NAMES[currentIndex+2]));
      add(imageLabel3, FlowLayout.RIGHT);
        
      }