Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Win;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.*;
- import java.util.*;
- import javax.swing.*;
- public class Izzy {
- //Important GUI structures
- static JFrame frame;
- static JTextArea input;
- static JTextArea output;
- static JPanel inputArea;
- static JPanel outputArea;
- static JPanel mainPanel;
- static JScrollPane scroller;
- static JButton activate;
- //File for dictionary
- static File dictionary;
- //Input text
- static String inputText = "";
- //Scanners for browsing dictionary and input text
- static Scanner fileScanner;
- static Scanner inputScanner;
- //Array for inputed characters
- static String[] characters;
- //is the program already calculating?
- static boolean buttonPressed;
- //Number of words found
- static int words;
- public static void main(String[] args){
- //initialize the GUI
- initGUI();
- //initialize the dictionary, array and other variables
- init();
- }
- public static void initGUI(){
- //frame
- frame = new JFrame("How to Beat Izzy Walter at Scrabble");
- frame.setSize(400,300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //main panel
- mainPanel = new JPanel();
- mainPanel.setSize(400,300);
- //button
- activate = new JButton("Cheat");
- activate.setPreferredSize(new Dimension(80,30));
- activate.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent arg0) {
- if(!buttonPressed){
- output.append("\n" + "Calculating Combinations...");
- inputText = input.getText();
- buttonPressed = true;
- calculateWords();
- }
- }//end action performed
- });
- //input text area
- input = new JTextArea("input");
- input.setPreferredSize(new Dimension(380,90));
- input.setLineWrap(true);
- //output text area
- output = new JTextArea("output");
- output.setEditable(false);
- output.setPreferredSize(new Dimension(200,999999999));
- output.setLineWrap(true);
- output.setWrapStyleWord(true);
- //input frame
- inputArea = new JPanel();
- inputArea.setPreferredSize(new Dimension(380,130));
- //output frame
- outputArea = new JPanel();
- outputArea.setPreferredSize(new Dimension(380,130));
- //scroll pane
- scroller = new JScrollPane(output);
- scroller.setPreferredSize(new Dimension(380,130));
- //add all the parts to their panels
- inputArea.add(input);
- inputArea.add(activate);
- outputArea.add(scroller);
- //add the main panel to the frame, and the other panels to the main panel
- frame.add(mainPanel);
- mainPanel.add(inputArea);
- mainPanel.add(scroller);
- //make it all seen!
- frame.setVisible(true);
- }//end initGUI
- public static void init(){
- //init the dictionary file
- dictionary = new File("fulldictionary00.txt");
- //init the array
- characters = new String[10];
- }//end init
- //I'm gonna have to do this a lot
- public static void initFileScanner(){
- //try to init the file scanner
- try {
- fileScanner = new Scanner(dictionary);
- } catch (FileNotFoundException e) {System.out.println("Scanner screwed up");}
- }
- public static void calculateWords(){
- getArray();
- for(int i = 0; i<characters.length; i++){
- for(int j = 0; j < characters.length; j++){
- for(int k = 0; k < characters.length; k++){
- for(int l = 0; l < characters.length; l++){
- for(int m = 0; m < characters.length; m++){
- for(int n = 0; n < characters.length; n++ ){
- for(int o =0; o < characters.length; o++){
- for(int p = 0; p < characters.length; p++){
- for(int q = 0; q < characters.length; q++){
- for(int r = 0; r < characters.length; r++){
- initFileScanner();
- while(fileScanner.hasNextLine()){
- if((characters[i] + characters[j] + characters[k]).equals(fileScanner.nextLine())){
- output.append("\n" + characters[i] + characters[j] + characters[k]);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- output.append("\n" + "Done!");
- buttonPressed = false;
- }//end calculateWords
- public static void getArray(){
- //init input scanner (now because if not the given string will never change)
- inputScanner = new Scanner(inputText);
- inputScanner.useDelimiter(",");
- for(int i=0; i<characters.length; i++){
- if(inputScanner.hasNext())
- characters[i] = inputScanner.next();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment