Advertisement
stonecold913

NEED HELP

Jun 7th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.19 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.nio.file.Files;
  4.  
  5. import javax.swing.*;
  6.  
  7. import java.awt.*;
  8. import java.awt.event.*;
  9.  
  10.  
  11. public class FinalGUI implements ActionListener
  12. {
  13.     JFrame slideShow;
  14.     JButton foward, backwards;
  15.     JPanel contentPane;
  16.     JTextArea slideNumber;
  17.     JLabel userPicture;
  18.     String path = "C:\\Documents and Settings\\James\\My Documents\\Dropbox\\Eclipse\\Final\\pics";  
  19.     File folder;
  20.     File[] listOfFiles;
  21.     ImageIcon[] icons;
  22.     int picNum=0;
  23.    
  24.    
  25.    
  26.    
  27.     public FinalGUI()
  28.     {
  29.        
  30.         slideShow = new JFrame("Slide Show");
  31.         slideShow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  32.        
  33.         contentPane = new JPanel();
  34.         contentPane.setLayout(new GridLayout (3, 0, 0, 0));
  35.        
  36.         JButton forword=new JButton("Forword");
  37.         forword.setActionCommand("forword");
  38.         forword.addActionListener(this);
  39.         contentPane.add(forword);
  40.        
  41.         folder = new File(path);
  42.         listOfFiles = folder.listFiles();
  43.        
  44.         icons = new ImageIcon[listOfFiles.length];
  45.  
  46.         for(int i=0; i<listOfFiles.length;i++)
  47.         {
  48.                 icons[i]=new ImageIcon(listOfFiles[i].getName());
  49.                 System.out.println("yes");
  50.         }
  51.        
  52.         JLabel userPicture = new JLabel(icons[0]);
  53.         contentPane.add(userPicture);
  54.        
  55.         JButton backwards = new JButton("Back");
  56.         backwards.setActionCommand("back");
  57.         backwards.addActionListener(this);
  58.         backwards.setEnabled(false);
  59.         contentPane.add(backwards);
  60.        
  61.        
  62.        
  63.         slideShow.setContentPane(contentPane);
  64.          
  65.         slideShow.pack();
  66.         slideShow.setVisible(true);
  67.     }
  68.    
  69.     public void actionPerformed(ActionEvent event)
  70.     {
  71.        
  72.         String eventName = event.getActionCommand();
  73.         System.out.println(icons[1].toString());
  74.        
  75.         if (eventName.equals("forword"))
  76.         {
  77.             picNum++;
  78.             userPicture.setIcon(icons[picNum]);
  79.         }
  80.        
  81.         if(eventName.equals("back"))
  82.         {
  83.             picNum--;
  84.             userPicture.setIcon(icons[picNum]);
  85.         }
  86.        
  87.         if(picNum>=1)
  88.             backwards.setEnabled(true);
  89.     }
  90.     private static void runGUI()
  91.     {
  92.         JFrame.setDefaultLookAndFeelDecorated(true);
  93.        
  94.         FinalGUI greeting = new FinalGUI();
  95.     }
  96.  
  97.     public static void main(String [] args)
  98.     {
  99.         javax.swing.SwingUtilities.invokeLater(new Runnable(){
  100.             public void run(){
  101.                 runGUI();
  102.             }
  103.         });
  104.     }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement