Advertisement
Guest User

Raffle Selector Code

a guest
Feb 2nd, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5. import java.util.Scanner;
  6.  
  7. import javax.swing.JFileChooser;
  8. import javax.swing.JOptionPane;
  9. import javax.swing.JTextArea;
  10.  
  11. public class RaffleSelector {
  12.  
  13.     public static void main(String args[]) throws FileNotFoundException {
  14.  
  15.         ArrayList<String> sentences = new ArrayList<String>();
  16.         String temp;
  17.         JFileChooser chooser = new JFileChooser();
  18.         File infile = null;
  19.         if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
  20.             infile = chooser.getSelectedFile();
  21.         }
  22.         Scanner input = new Scanner(infile);
  23.         while (input.hasNextLine()) {
  24.             temp = input.nextLine();
  25.             sentences.add(temp);
  26.         }
  27.         Random r = new Random();
  28.         String line = sentences.get(r.nextInt(sentences.size()));
  29.         JTextArea textArea = new JTextArea();
  30.         textArea.setText(line);
  31.         textArea.setColumns(50);
  32.         textArea.setOpaque(false);
  33.         textArea.setEditable(false);
  34.         textArea.setLineWrap(true);
  35.         textArea.setWrapStyleWord(true);
  36.         JOptionPane.showMessageDialog(null, textArea);
  37.         System.out.println(line);
  38.  
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement