Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import java.util.Random;
- import java.util.Scanner;
- import javax.swing.JFileChooser;
- import javax.swing.JOptionPane;
- import javax.swing.JTextArea;
- public class RaffleSelector {
- public static void main(String args[]) throws FileNotFoundException {
- ArrayList<String> sentences = new ArrayList<String>();
- String temp;
- JFileChooser chooser = new JFileChooser();
- File infile = null;
- if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
- infile = chooser.getSelectedFile();
- }
- Scanner input = new Scanner(infile);
- while (input.hasNextLine()) {
- temp = input.nextLine();
- sentences.add(temp);
- }
- Random r = new Random();
- String line = sentences.get(r.nextInt(sentences.size()));
- JTextArea textArea = new JTextArea();
- textArea.setText(line);
- textArea.setColumns(50);
- textArea.setOpaque(false);
- textArea.setEditable(false);
- textArea.setLineWrap(true);
- textArea.setWrapStyleWord(true);
- JOptionPane.showMessageDialog(null, textArea);
- System.out.println(line);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement