Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.IOException;
- import java.nio.file.Files;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class FinalGUI implements ActionListener
- {
- JFrame slideShow;
- JButton foward, backwards;
- JPanel contentPane;
- JTextArea slideNumber;
- JLabel userPicture;
- String path = "C:\\Documents and Settings\\James\\My Documents\\Dropbox\\Eclipse\\Final\\pics";
- File folder;
- File[] listOfFiles;
- ImageIcon[] icons;
- int picNum=0;
- public FinalGUI()
- {
- slideShow = new JFrame("Slide Show");
- slideShow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- contentPane = new JPanel();
- contentPane.setLayout(new GridLayout (3, 0, 0, 0));
- JButton forword=new JButton("Forword");
- forword.setActionCommand("forword");
- forword.addActionListener(this);
- contentPane.add(forword);
- folder = new File(path);
- listOfFiles = folder.listFiles();
- icons = new ImageIcon[listOfFiles.length];
- for(int i=0; i<listOfFiles.length;i++)
- {
- icons[i]=new ImageIcon(listOfFiles[i].getName());
- System.out.println("yes");
- }
- JLabel userPicture = new JLabel(icons[0]);
- contentPane.add(userPicture);
- JButton backwards = new JButton("Back");
- backwards.setActionCommand("back");
- backwards.addActionListener(this);
- backwards.setEnabled(false);
- contentPane.add(backwards);
- slideShow.setContentPane(contentPane);
- slideShow.pack();
- slideShow.setVisible(true);
- }
- public void actionPerformed(ActionEvent event)
- {
- String eventName = event.getActionCommand();
- System.out.println(icons[1].toString());
- if (eventName.equals("forword"))
- {
- picNum++;
- userPicture.setIcon(icons[picNum]);
- }
- if(eventName.equals("back"))
- {
- picNum--;
- userPicture.setIcon(icons[picNum]);
- }
- if(picNum>=1)
- backwards.setEnabled(true);
- }
- private static void runGUI()
- {
- JFrame.setDefaultLookAndFeelDecorated(true);
- FinalGUI greeting = new FinalGUI();
- }
- public static void main(String [] args)
- {
- javax.swing.SwingUtilities.invokeLater(new Runnable(){
- public void run(){
- runGUI();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement