Advertisement
madhawaseeeee

Untitled

Sep 24th, 2015
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. import java.awt.event.ActionEvent;
  2. import java.awt.event.ActionListener;
  3. import javax.swing.*;
  4.  
  5. import java.io.File;
  6. import java.io.IOException;
  7. import javax.imageio.ImageIO;
  8.  
  9. public class ListView implements ActionListener {
  10.  
  11.     private JFrame frame;
  12.  
  13.     int i = 0;
  14.     JLabel jLabel1;
  15.  
  16.     public ListView() throws IOException {
  17.         String path = "/home/vipul/Downloads/Images/JPEG";
  18.         frame = new JFrame();
  19.         frame.setSize(800, 800);
  20.         JButton next = new JButton("NEXT");
  21.         next.addActionListener(this);
  22.         jLabel1 = new JLabel("lab");
  23.         jLabel1.setOpaque(true);
  24.         next.setBounds(400, 400, 200, 150);
  25.         frame.add(next);
  26.         jLabel1.setBounds(500, 200, 100, 100);
  27.         frame.add(jLabel1);
  28.  
  29.         //   next.addActionListener(this);
  30.         frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  31.  
  32.         File folder = new File(path);
  33.         File[] listOfFiles = folder.listFiles();
  34.         DefaultListModel listModel = new DefaultListModel();
  35.         int count = 0;
  36.         for (int i = 0; i < listOfFiles.length; i++) {
  37.             System.out.println("check path" + listOfFiles[i]);
  38.             String name = listOfFiles[i].toString();
  39.             // load only JPEGs
  40.             if (name.endsWith("jpg")) {
  41.                 ImageIcon ii = new ImageIcon(ImageIO.read(listOfFiles[i]));
  42.                 listModel.add(count++, ii);
  43.             }
  44.         }
  45.         JList lsm = new JList(listModel);
  46.         lsm.setVisibleRowCount(1);
  47.  
  48.         frame.add(new JScrollPane(lsm));
  49.  
  50.         frame.pack();
  51.         frame.setVisible(true);
  52.     }
  53.  
  54.     public static void main(String[] args) throws IOException {
  55.         new ListView();
  56.     }
  57.  
  58.     @Override
  59.     public void actionPerformed(ActionEvent e) {
  60.         i++;
  61.  
  62.         ImageIcon imgThisImg = new ImageIcon("/home/vipul/Downloads/Images/JPEG/"+i+".jpg");
  63.         System.out.println("mage path ?? " + imgThisImg);
  64.         jLabel1.setIcon(imgThisImg);
  65.         frame.revalidate();
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement