Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hashtable;
- import java.io.File;
- import java.io.IOException;
- import java.util.Hashtable;
- import java.util.Scanner;
- import javafx.application.Application;
- import javafx.event.Event;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.input.MouseEvent;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.HBox;
- import javafx.stage.FileChooser;
- import javafx.stage.Stage;
- public class HashTableTest extends Application
- {
- @Override
- public void start(Stage primaryStage)
- {
- Button importButton = new Button(" Import File ");
- /** button to solve the maze */
- importButton.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<Event>()
- {
- @Override
- public void handle(Event event)
- {
- fileReader(primaryStage);
- }
- });
- HBox footer = new HBox();
- footer.setId("headingBox");
- footer.getChildren().addAll(importButton);
- BorderPane bp = new BorderPane();
- bp.setBottom(footer);
- //bp.setCenter();
- Scene scene = new Scene(bp);
- scene.getStylesheets().add("stack_maze/CssFile.css");
- primaryStage.setScene(scene); // Place the scene in the stage
- primaryStage.show(); // Display the stage
- }
- /** Main method to launch the javafx
- * @param args main method argument
- */
- public static void main(String[] args)
- {
- launch(args);
- //E names;
- String key;
- // Creating a Hashtable
- Hashtable<String, String> hashtable =
- new Hashtable<String, String>();
- // Adding Key and Value pairs to Hashtable
- hashtable.put("Key1","Chaitanya");
- hashtable.put("Key2","Ajeet");
- hashtable.put("Key3","Peter");
- hashtable.put("Key4","Ricky");
- hashtable.put("Key5","Mona");
- //names = hashtable.keys();
- //while(names.hasMoreElements()) {
- // key = (String) names.nextElement();
- // System.out.println("Key: " +key+ " & Value: " +
- // hashtable.get(key));
- }
- public void fileReader(Stage primaryStage)
- {
- FileChooser fileChooser = new FileChooser();
- // Setting it so you can only import text files
- FileChooser.ExtensionFilter extFilter =
- new FileChooser.ExtensionFilter("TEXT files (*.txt)", "*.txt");
- fileChooser.getExtensionFilters().add(extFilter);
- // Show buttons to start program
- File file = fileChooser.showOpenDialog(primaryStage);
- if (file != null)
- {
- try
- {
- Scanner in = new Scanner(file);
- SimpleList sl = new SimpleList();
- String line = in.nextLine();
- String[] words = line.split(" ");
- for(int i = 0; i < words.length; i++)
- {
- String wordCheck = words[i].toLowerCase();
- int wordIndex = sl.find(wordCheck);
- if(wordIndex > -1)
- {
- sl.getEntry(wordIndex).incrementCount();
- }
- else
- {
- Entry newEntry = new Entry(wordCheck);
- sl.add(newEntry);
- }
- sl.toString();
- }
- }
- catch(IOException e)
- {
- System.err.println(e);
- System.exit(1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement