Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- import java.io.File;
- import java.io.IOException;
- import javax.imageio.ImageIO;
- public class ListView implements ActionListener {
- private JFrame frame;
- int i = 0;
- JLabel jLabel1;
- public ListView() throws IOException {
- String path = "/home/vipul/Downloads/Images/JPEG";
- frame = new JFrame();
- frame.setSize(800, 800);
- JButton next = new JButton("NEXT");
- next.addActionListener(this);
- jLabel1 = new JLabel("lab");
- jLabel1.setOpaque(true);
- next.setBounds(400, 400, 200, 150);
- frame.add(next);
- jLabel1.setBounds(500, 200, 100, 100);
- frame.add(jLabel1);
- // next.addActionListener(this);
- frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- File folder = new File(path);
- File[] listOfFiles = folder.listFiles();
- DefaultListModel listModel = new DefaultListModel();
- int count = 0;
- for (int i = 0; i < listOfFiles.length; i++) {
- System.out.println("check path" + listOfFiles[i]);
- String name = listOfFiles[i].toString();
- // load only JPEGs
- if (name.endsWith("jpg")) {
- ImageIcon ii = new ImageIcon(ImageIO.read(listOfFiles[i]));
- listModel.add(count++, ii);
- }
- }
- JList lsm = new JList(listModel);
- lsm.setVisibleRowCount(1);
- frame.add(new JScrollPane(lsm));
- frame.pack();
- frame.setVisible(true);
- }
- public static void main(String[] args) throws IOException {
- new ListView();
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- i++;
- ImageIcon imgThisImg = new ImageIcon("/home/vipul/Downloads/Images/JPEG/"+i+".jpg");
- System.out.println("mage path ?? " + imgThisImg);
- jLabel1.setIcon(imgThisImg);
- frame.revalidate();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement