Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ib2;
- import java.awt.Scrollbar;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseListener;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.PrintWriter;
- import java.util.Scanner;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JLayeredPane;
- import javax.swing.JMenu;
- import javax.swing.JMenuItem;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- public class Gui extends JFrame implements ActionListener, MouseListener {
- private JMenu menu, submenu;
- private JMenuItem Decks, Options;
- private static String loc = "C:\\Users\\huber\\OneDrive\\Dokumenty\\Folder szkolny\\Forms\\Program Data";
- private JLayeredPane screen;
- private static Boolean b = true;
- void Menubar() {
- }
- static String getLoc() {
- return loc;
- }
- static void setB(boolean b) {
- }
- static boolean getB() {
- return b;
- }
- static char[] setLocal(String a) {
- char[] ch = new char[a.length()];
- for (int i = 0; i < a.length(); i++) {
- ch[i] = a.charAt(i);
- if (ch[i] == '\'' && i == a.length() - 1) {
- ch[i + 1] = '\'';
- i++;
- }
- }
- return ch;
- }
- static String setLoc(String loc) {
- loc = Gui.loc;
- return loc;
- }
- public static void main(String[] args) throws IOException {
- System.out.println("Current location of files: " + getLoc());
- System.out.println("Do you want to change it?\n" + "\t1. Yes\n" + "\t2. No");
- Scanner c = new Scanner(System.in);
- if (c.nextInt() == 1) {
- System.out.println(
- "\nInput a new location (Warning: you will have to manually transport all files from current location to a new location.");
- Scanner s = new Scanner(System.in);
- char[] ch = setLocal(s.nextLine());
- setLoc(new String(ch));
- if (getLoc().equals(new String(ch)))
- System.out.println("Your new location for the program's files is " + getLoc());
- File g = new File(getLoc() + "\\directory.txt");
- g.createNewFile();
- FileWriter mn = new FileWriter(g);
- BufferedWriter pl = new BufferedWriter(mn);
- PrintWriter writer = new PrintWriter(g);
- writer.print("");
- writer.close();
- pl.write(getLoc());
- pl.close();
- c.close();
- s.close();
- }
- File gp = new File(getLoc() + "\\directory.txt");
- gp.createNewFile();
- FileWriter mnp = new FileWriter(gp);
- BufferedWriter plp = new BufferedWriter(mnp);
- plp.write(getLoc());
- setLoc(gp.toString());
- plp.close();
- System.out.println("Welcome to Flashcard Program vBeta\n" + "What you want to do?\n"
- + "\t1. Display a list of decks\n" + "\t2. Create a new deck\n"
- // + "\t3. Set destination folder for flashcards (recommended for the first
- // time)\n"
- + "\t4. What you want to be shown first in traditional view of flashbacks?\n"
- + "\t5. Import deck from a deck");
- Scanner scan = new Scanner(System.in);
- int sc = scan.nextInt();
- if (sc == 1) {
- System.out.println("Choose a deck");
- File f = new File(getLoc() + "\\flashcardList.txt");
- f.createNewFile();
- BufferedReader br1 = new BufferedReader(new FileReader(f));
- int liczbalinijek = 0;
- while (br1.readLine() != null) {
- liczbalinijek++;
- }
- br1.close();
- BufferedReader br2 = new BufferedReader(new FileReader(f));
- String[] s = new String[liczbalinijek];
- if (liczbalinijek == 0) {
- System.out.println("There are no decks currentely created.");
- }
- for (int i = 0; i < liczbalinijek; i++) {
- s[i] = br2.readLine();
- System.out.println(s[i]);
- }
- br2.close();
- Scanner dn = new Scanner(System.in);
- String dnt = dn.nextLine();
- for (int i = 0; i < liczbalinijek; i++) {
- if (s[i].equals(dnt)) {
- File d = new File(getLoc() + "\\" + s[i] + ".txt");
- BufferedReader subbf1 = new BufferedReader(new FileReader(d));
- int ll = 0;
- BufferedReader subbf2 = new BufferedReader(new FileReader(d));
- while (subbf1.readLine() != null) {
- ll++;
- System.out.println(subbf2.readLine() + "\n");
- }
- subbf1.close();
- subbf2.close();
- System.out.println("Options:" + "\n1. Switch to the traditional view."
- + "\n2. Launch a matching app" + "\n3. Add a new flashcard");
- Scanner flashcard = new Scanner(System.in);
- Flashcard[] fclist = new Flashcard[ll];
- Deck deck = new Deck(dnt, fclist);
- deck.setFclist(d);
- if (flashcard.nextInt() == 1) {
- System.out.println("Which flashcard you'd want to see? (Write it's number)");
- Scanner sy = new Scanner(System.in);
- int y = sy.nextInt() - 1;
- if (getB()) {
- System.out.println(deck.getFclist()[y].getTerm() + "\n");
- } else {
- System.out.println(deck.getFclist()[y].getDefinition() + "\n");
- }
- System.out.println("\t1. Show the other side of the flashcard");
- Scanner trview = new Scanner(System.in);
- if (trview.nextInt() == 1)
- if (getB()) {
- System.out.println("\n" + deck.getFclist()[y].getDefinition() + "\n");
- } else {
- System.out.println("\n" + deck.getFclist()[y].getTerm() + "\n");
- }
- }
- if (flashcard.nextInt() == 2) {
- String[] a = new String[2 * ll];
- // int[] bt = new int[ll];
- // int[] bd = new int[ll];
- // for (int l = 0; l < ll; l++) {
- // bt[l] = ll + 1;
- // bd[l] = ll + 1;
- // }
- int checkterm = 0;
- for (int t = 0; t < 2 * ll; t++) {
- int p = (int) Math.random();
- if (p % 2 == 0) {
- if (checkterm != ll) {
- a[t] = deck.getFclist()[(int) (Math.random() * (ll))].getTerm();
- boolean check1 = true;
- int check2 = 0;
- for (int g = 0; check2 == 2 * ll; g++) {
- // if (p == bt[g]) {
- // p = (int) Math.random();
- // g = 0;
- // }
- // }
- if (a[t].equals(a[g])) {
- a[t] = deck.getFclist()[(int) (Math.random() * (ll))].getTerm();
- check1 = false;
- }
- if (check1)
- check2++;
- if (g == ll - 1) {
- g = 0;
- }
- // bt[t] = p;
- }
- System.out.println(a[t]);
- checkterm++;
- }
- }
- else {
- a[t] = deck.getFclist()[(int) (Math.random() * (ll))].getDefinition();
- boolean check1 = true;
- int check2 = 0;
- for (int g = 0; check2 == 2 * ll; g++) {
- // if (p == bt[g]) {
- // p = (int) Math.random();
- // g = 0;
- // }
- // }
- if (a[t].equals(a[g])) {
- a[t] = deck.getFclist()[(int) (Math.random() * (ll))].getDefinition();
- check1 = false;
- }
- if (check1)
- check2++;
- if (g == ll - 1) {
- g = 0;
- }
- // bt[t] = p;
- }
- System.out.println(a[t]);
- }
- }
- double score = 0;
- int check = 0;
- while (check != 2 * ll) {
- System.out.println("Your current score: 0\n"
- + "join together term and definition (seperate them by tabulator)");
- Scanner v = new Scanner(System.in);
- char[] t1 = new char[v.nextLine().length()];
- char[] d1 = new char[v.nextLine().length()];
- int k = 0;
- for (int z = 0; z < v.nextLine().length(); z++) {
- t1[z] = v.nextLine().charAt(z);
- if (v.nextLine().charAt(z) == '\t' || k == 1) {
- d1[z] = v.nextLine().charAt(z);
- k = 1;
- }
- }
- String T1 = new String(t1);
- String D1 = new String(d1);
- int ff = 0;
- int fail = 0;
- for (int z = 0; z < ll; z++) {
- if (T1.equals(fclist[z].getTerm()) && D1.equals(fclist[z].getDefinition())) {
- System.out.println("That's the correct answer!");
- score++;
- check++;
- ff = z;
- } else {
- fail++;
- }
- if (a[z].equals(fclist[ff].getTerm()) || a[z].equals(fclist[ff].getDefinition())) {
- a[z] = "";
- }
- }
- if (fail == ll) {
- System.out.println("I'm sorry, but that was a wrong answer.");
- score--;
- }
- }
- System.out.println("Type down your name.");
- Scanner nameUser = new Scanner(System.in);
- UserApp u = new UserApp(nameUser.nextLine(), score);
- File rl = new File(getLoc() + "\\rankingList.txt");
- if (rl.createNewFile()) {
- BufferedWriter bw1 = new BufferedWriter(new FileWriter(rl));
- for (int j = 1; j <= 10; j++) {
- if (j == 1)
- bw1.write(j + "." + "\t" + u.getUserName() + "\t" + u.getScore() + "\n");
- else
- bw1.write(j + ".\t\t\n");
- }
- } else {
- setUserList(rl, u); // make it later
- }
- System.out.println("Your score is " + score + " points.");
- System.out.println("\tRanking:");
- BufferedReader br3 = new BufferedReader(new FileReader(rl));
- while (br3.readLine() != null)
- System.out.println(br3.readLine());
- br3.close();
- }
- if (flashcard.nextInt() == 3) {
- FileWriter fw = new FileWriter(d);
- BufferedWriter bw = new BufferedWriter(fw);
- System.out.println("How many flashcards you'd want to add?");
- Scanner s1 = new Scanner(System.in);
- for (int z = 0; z < s1.nextInt(); z++) {
- System.out.println("Write the term of additional flashcard number " + z + ".");
- Scanner t = new Scanner(System.in);
- System.out.println("Write the definition of additional flashcard number " + z + ".");
- Scanner def = new Scanner(System.in);
- bw.write(t.nextLine() + "\t" + def.nextLine() + "\n");
- }
- bw.close();
- }
- flashcard.close();
- break;
- }
- }
- dn.close();
- }
- if (sc == 2) {
- String name;
- System.out.println("Write the name of the deck");
- Scanner s1 = new Scanner(System.in);
- name = s1.nextLine();
- System.out.println("Write how many flashcards do you want to be in the deck");
- Scanner s2 = new Scanner(System.in);
- int ll = s2.nextInt();
- Flashcard[] fclist = new Flashcard[ll];
- File ff = new File(getLoc() + "//" + name + ".txt");
- ff.createNewFile();
- String term = "";
- String definition = "";
- FileWriter deckSource = new FileWriter(ff);
- BufferedWriter bw = new BufferedWriter(deckSource);
- for (int i = 0; i < ll; i++) {
- System.out.println("Write the term of the flashcard number " + i + ".");
- Scanner t = new Scanner(System.in);
- fclist[i] = new Flashcard(term, definition);
- if (!t.toString().equals("")) {
- fclist[i].setTerm(t.nextLine());
- }
- System.out.println("Write the definition of the flashcard number " + i + ".");
- Scanner de = new Scanner(System.in);
- if (!de.toString().equals(""))
- fclist[i].setDefinition(de.nextLine());
- bw.write(fclist[i].getTerm() + "\t" + fclist[i].getDefinition() + "\n");
- }
- bw.close();
- File e = new File(getLoc() + "//flashcardList.txt");
- e.createNewFile();
- FileWriter deckListSource = new FileWriter(e);
- BufferedWriter wb = new BufferedWriter(deckListSource);
- wb.write(name + "\n");
- wb.close();
- }
- // if (sc == 3) {
- // System.out.println("Current location of files:" + getLoc()
- // + "\nInput a new location (Warning: you will have to manually transport all files from current location to a new location.");
- // Scanner s = new Scanner(System.in);
- // char[] ch = setLocal(s.nextLine());
- // setLoc(new String(ch));
- // if (getLoc().equals(new String(ch)))
- // System.out.println("Your new location for the program's files is" + getLoc());
- //
- // }
- if (sc == 4)
- {
- Scanner p = new Scanner(System.in);
- int pint = p.nextInt();
- if (getB()) {
- System.out.println(
- "Currently, the term is shown first" + "\nDo you want to change it?" + "\n1.Yes" + "\n2.No");
- if (pint == 1)
- setB(false);
- } else {
- System.out.println("Currently, the definition is shown first" + "\nDo you want to change it?"
- + "\n1.Yes" + "\n2.No");
- if (pint == 1)
- setB(false);
- }
- if (pint == 2) {
- }
- }
- if (sc == 5) {
- System.out.println("Write down the path direction of the file");
- Scanner scr = new Scanner(System.in);
- System.out.println("Write down the of the file");
- Scanner name = new Scanner(System.in);
- File fff = new File(setLocal(scr.nextLine()) + name.nextLine() + ".txt");
- fff.createNewFile();
- InputStream is = null;
- OutputStream os = null;
- try {
- is = new FileInputStream(new String(setLocal(scr.nextLine())));
- os = new FileOutputStream(getLoc());
- byte[] buffer = new byte[1024];
- int length;
- while ((length = is.read(buffer)) > 0) {
- os.write(buffer, 0, length);
- }
- } finally {
- is.close();
- os.close();
- }
- File e = new File(getLoc() + "//flashcardList.txt");
- FileWriter deckListSource = new FileWriter(e);
- BufferedWriter wb = new BufferedWriter(deckListSource);
- wb.write(name.nextLine() + "\n");
- wb.close();
- }
- scan.close();
- }
- private static void setUserList(File rl, UserApp u) throws IOException {
- Scanner lr = new Scanner(rl);
- BufferedReader brbr = new BufferedReader(new FileReader(rl));
- char[] nch;
- char[] sch;
- UserApp[] ua = new UserApp[10];
- int check = 0;
- while (check != 1) {
- String s = brbr.readLine();
- nch = new char[s.length()];
- for (int i = 3; i < s.length(); i++) {
- nch[i] = s.charAt(i);
- }
- }
- }
- static class Deck extends Gui {
- private String name;
- private JLabel[] termList, definitionList;
- private Scrollbar sFlashcards;
- private JLabel termAndDefinition, message;
- private JButton addNewFlashcard, switching, cancel, done, Previous, Next, showOtherSide;
- private JLayeredPane pane;
- private JTextField nameOrTerm;
- private int ll = 0;
- private Flashcard[] fclist = new Flashcard[ll];
- Flashcard[] setFclist(File f) throws IOException {
- BufferedReader br1 = new BufferedReader(new FileReader(f));
- BufferedReader br2 = new BufferedReader(new FileReader(f));
- while (br1.readLine() != null)
- ll++;
- Flashcard[] fclist = new Flashcard[ll];
- String s;
- for (int z = 0; (s = br2.readLine()) != null; z++) {
- fclist[z] = new Flashcard("", "");
- char[] ch = new char[s.length()];
- char[] ch2 = new char[s.length()];
- int index = 0;
- for (int i = 0; s.charAt(i) != '\t'; i++) {
- ch[i] = s.charAt(i);
- index = i + 2;
- }
- fclist[z].setTerm(new String(ch));
- for (int x = index; x < s.length(); x++) {
- ch2[x] = s.charAt(x);
- }
- fclist[z].setDefinition(new String(ch2));
- }
- br1.close();
- br2.close();
- this.fclist = fclist;
- return fclist;
- }
- public String getName() {
- return name;
- }
- Flashcard[] getFclist() {
- return fclist;
- }
- Deck(String name, Flashcard[] fclist) {
- this.name = name;
- this.fclist = fclist;
- }
- void deckNamePrompt() {
- // generate a prompt for inputting the name upon creating new deck
- // flashcardListOverview() flashcardListTraditional() //two methods for
- // different presentation of flashcards
- }
- }
- static class Flashcard extends Gui {
- private String term, definition;
- private JTextField definitionShow;
- private JButton addNextFlashcard;
- Flashcard(String term, String definition) {
- setTerm(term);
- setDefinition(definition);
- }
- String getTerm() {
- return term;
- }
- String getDefinition() {
- return definition;
- }
- void setTerm(String term) {
- this.term = term;
- }
- void setDefinition(String definition) {
- this.definition = definition;
- }
- void flashcardPrompt() {
- // generating a prompt for inputting a term and definition for a flashcard
- }
- }
- static class Decklist extends Gui {
- private Deck[] deckArray;
- private JButton[] theDeckList;
- private JLabel nameOfDecks;
- private Scrollbar sDeckList;
- void decklistInterface() {
- }
- Decklist(Deck[] deckArray) {
- this.deckArray = deckArray;
- }
- void setDeckArray(File decklistNameSource) {
- }
- Deck[] getDeckArray() {
- return deckArray;
- }
- }
- class Prompts extends Gui {
- private JButton ok;
- private JLabel message;
- private JLayeredPane prompt;
- void promptsWindow(String m) {
- }
- }
- @Override
- public void mouseClicked(MouseEvent e) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mousePressed(MouseEvent e) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseReleased(MouseEvent e) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseEntered(MouseEvent e) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseExited(MouseEvent e) {
- // TODO Auto-generated method stub
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- }
- }
- class Ranking extends Gui {
- private UserApp[] userList;
- private JLabel[] rankingList;
- private JLabel name, timeFinish, message;
- private JLayeredPane window;
- private JTextField direction;
- void rankingInterface() {
- }
- void prompt() {
- }
- void setUserList(File rl, UserApp u) {
- }
- UserApp[] getUserList() {
- return userList;
- }
- }
- class UserApp extends Gui {
- private String userName;
- private double score;
- UserApp(String userName, double score) {
- setUserName(userName);
- setScore(score);
- }
- String getUserName() {
- return userName;
- }
- double getScore() {
- return score;
- }
- void setUserName(String userName) {
- }
- void setScore(double score) {
- this.score = score;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement