TheGadgetCatTumblr

Scrabble Cheater

Feb 1st, 2012
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.72 KB | None | 0 0
  1. package Win;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.io.*;
  7. import java.util.*;
  8. import javax.swing.*;
  9.  
  10. public class Izzy {
  11.  
  12.     //Important GUI structures
  13.     static JFrame frame;
  14.     static JTextArea input;
  15.     static JTextArea output;
  16.     static JPanel inputArea;
  17.     static JPanel outputArea;
  18.     static JPanel mainPanel;
  19.     static JScrollPane scroller;
  20.     static JButton activate;
  21.    
  22.     //File for dictionary
  23.     static File dictionary;
  24.    
  25.     //Input text
  26.     static String inputText = "";
  27.    
  28.     //Scanners for browsing dictionary and input text
  29.     static Scanner fileScanner;
  30.     static Scanner inputScanner;
  31.    
  32.     //Array for inputed characters
  33.     static String[] characters;
  34.    
  35.     //is the program already calculating?
  36.     static boolean buttonPressed;
  37.    
  38.     //Number of words found
  39.     static int words;
  40.    
  41.     public static void main(String[] args){
  42.        
  43.         //initialize the GUI
  44.         initGUI();
  45.        
  46.         //initialize the dictionary, array and other variables
  47.         init();
  48.     }
  49.    
  50.     public static void initGUI(){
  51.        
  52.         //frame
  53.         frame = new JFrame("How to Beat Izzy Walter at Scrabble");
  54.         frame.setSize(400,300);
  55.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  56.        
  57.         //main panel
  58.         mainPanel = new JPanel();
  59.         mainPanel.setSize(400,300);
  60.        
  61.         //button
  62.         activate = new JButton("Cheat");
  63.         activate.setPreferredSize(new Dimension(80,30));
  64.         activate.addActionListener(new ActionListener(){
  65.            
  66.             public void actionPerformed(ActionEvent arg0) {
  67.                
  68.                 if(!buttonPressed){
  69.                    
  70.                     output.append("\n" + "Calculating Combinations...");
  71.                    
  72.                     inputText = input.getText();
  73.                     buttonPressed = true;
  74.                    
  75.                     calculateWords();  
  76.                 }
  77.             }//end action performed
  78.            
  79.         });
  80.        
  81.         //input text area
  82.         input = new JTextArea("input");
  83.         input.setPreferredSize(new Dimension(380,90));
  84.         input.setLineWrap(true);
  85.        
  86.         //output text area
  87.         output = new JTextArea("output");
  88.         output.setEditable(false);
  89.         output.setPreferredSize(new Dimension(200,999999999));
  90.         output.setLineWrap(true);
  91.         output.setWrapStyleWord(true);
  92.        
  93.         //input frame
  94.         inputArea = new JPanel();
  95.         inputArea.setPreferredSize(new Dimension(380,130));
  96.        
  97.         //output frame
  98.         outputArea = new JPanel();
  99.         outputArea.setPreferredSize(new Dimension(380,130));
  100.        
  101.         //scroll pane
  102.         scroller = new JScrollPane(output);
  103.         scroller.setPreferredSize(new Dimension(380,130));
  104.        
  105.         //add all the parts to their panels
  106.         inputArea.add(input);
  107.         inputArea.add(activate);
  108.         outputArea.add(scroller);
  109.        
  110.         //add the main panel to the frame, and the other panels to the main panel
  111.         frame.add(mainPanel);
  112.         mainPanel.add(inputArea);
  113.         mainPanel.add(scroller);
  114.        
  115.         //make it all seen!
  116.         frame.setVisible(true);
  117.        
  118.     }//end initGUI
  119.    
  120.     public static void init(){
  121.        
  122.         //init the dictionary file
  123.         dictionary = new File("fulldictionary00.txt");
  124.        
  125.         //init the array
  126.         characters = new String[10];
  127.        
  128.        
  129.     }//end init
  130.    
  131.     //I'm gonna have to do this a lot
  132.     public static void initFileScanner(){      
  133.         //try to init the file scanner
  134.         try {
  135.             fileScanner = new Scanner(dictionary);
  136.         } catch (FileNotFoundException e) {System.out.println("Scanner screwed up");}
  137.        
  138.     }
  139.    
  140.     public static void calculateWords(){
  141.        
  142.         getArray();
  143.        
  144.         for(int i = 0; i<characters.length; i++){
  145.            
  146.             for(int j = 0; j < characters.length; j++){
  147.                
  148.                 for(int k = 0; k < characters.length; k++){
  149.                
  150.                     for(int l = 0; l < characters.length; l++){
  151.                        
  152.                         for(int m = 0; m < characters.length; m++){
  153.                            
  154.                             for(int n = 0; n < characters.length; n++ ){
  155.                                
  156.                                 for(int o =0; o < characters.length; o++){
  157.                                    
  158.                                     for(int p = 0; p < characters.length; p++){
  159.                                        
  160.                                         for(int q = 0; q < characters.length; q++){
  161.                                            
  162.                                             for(int r = 0; r < characters.length; r++){
  163.                                                
  164.                                                 initFileScanner();
  165.                                                
  166.                                                 while(fileScanner.hasNextLine()){
  167.                                                     if((characters[i] + characters[j] + characters[k]).equals(fileScanner.nextLine())){
  168.                                                         output.append("\n" + characters[i] + characters[j] + characters[k]);
  169.                                                     }
  170.                                                 }
  171.                                                
  172.                                             }
  173.                                            
  174.                                         }
  175.                                        
  176.                                     }
  177.                                    
  178.                                 }
  179.                                
  180.                             }
  181.                            
  182.                         }
  183.                        
  184.                     }
  185.                    
  186.                 }
  187.             }
  188.         }
  189.        
  190.         output.append("\n" + "Done!");
  191.        
  192.         buttonPressed = false;
  193.     }//end calculateWords
  194.    
  195.     public static void getArray(){
  196.        
  197.         //init input scanner (now because if not the given string will never change)
  198.         inputScanner = new Scanner(inputText);
  199.         inputScanner.useDelimiter(",");
  200.        
  201.         for(int i=0; i<characters.length; i++){
  202.             if(inputScanner.hasNext())
  203.                 characters[i] = inputScanner.next();
  204.         }
  205.        
  206.     }
  207.    
  208. }
Advertisement
Add Comment
Please, Sign In to add comment