Untitled

 avatar
unknown
plain_text
5 years ago
2.6 kB
7
Indexable
package tsoulos.exam;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Random;
import java.util.Scanner;

class MyScrambleGame{
    private JFrame jframe;
    private String wordList[] = new String[100];
    private int numberOfWords = 0;
    JLabel lbl;
    JTextField text;
    String word;

    public MyScrambleGame() throws IOException {
        File file =new File("words.txt");
        file.createNewFile();
        Scanner sc = new Scanner(file);
        int i=0;
        while(sc.hasNext()){
            wordList[i] = sc.nextLine();
            i++;

        }
        numberOfWords=i;


        lbl = new JLabel();
        jframe= new JFrame("ΛΕΞΟΜΑΝΤΕΙΑ");
        JPanel content= new JPanel();
        jframe.add(content);
        text=new JTextField();

        JLabel lbl = new JLabel();
        JTextField text=new JTextField();
        text.setColumns(20);
        content.add(lbl);
        content.add(text);
        JButton btn = new JButton("Try");
        content.add(btn);
        content.setVisible(true);
        content.setSize(200,100);
        jframe.setVisible(true);
        jframe.setSize(300,150);
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                check();

            }
        });
        game();



    }
    public void check(){
        if(text.getText().equals(word)){
            System.out.println("ΣΩΣΤΟ");
        }
        else{
            System.out.println("Lathos");

        }

    }

    public void game(){
            word=fetch();
            String scr=scrable(word);
            lbl.setText(scr);



    }


    public static String scrable(String word) {

        char[] character = word.toCharArray();
        String scr = null;
        for(int i = 0; i < character.length; i ++)
        {
            char[] java = new char [(int)Math.random()*i] ;
            scr = new String(java);
        }

        return scr;
    }

    public String fetch(){
        Random r = new Random();
        int rand = r.nextInt(numberOfWords);

        return wordList[rand];

    }










}


public class Main {


    private String wordList[] = new String[100];
    private int numberOfWords = 0;

    public static void main(String[] args) throws IOException {
        new MyScrambleGame();
    }
}
Editor is loading...